import { game, ui, _status, ai, lib, get } from "../../../../../noname.js";
export default {
	//_ywzq_np: {
	//	trigger: {
	//		global: ["gameStart"],
	//		player: ["phaseBeginStart", "useCardBegin", "damageBegin", "gainBegin", "np_change"],
	//		source: "damageBegin"
	//	},
	//	marktext: "Np",
	//	intro: {
	//		name: `
	//                          <div style="text-align:center">
	//                          <div style="font-size:1.2em">${_status.event.player?.ywzq.Name || "灵气值"}</div>
	//                          <div style="font-size:0.7em; white-space:nowrap; color:${lib.config.menu_style == "wood" ? "888" : "#aaa"}">用于《勇往直前》扩展</div>
	//                          </div>
	//                      `,
	//		markcount(storage, player) {
	//			return player.ywzq.Np;
	//		},
	//		content(storage, player) {
	//			return game.NpContent();
	//		},
	//		//markimage: "https://img1.baidu.com/it/u=2019848873,3749180421&fm=253&fmt=auto&app=138&f=PNG?w=304&h=304",
	//	},
	//	lastDo: true,
	//	forced: true,
	//	popup: false,
	//	silent: true,
	//	fixed: true,
	//	superCharlotte: true,
	//	create(player) {
	//		game.broadcastAll(function (player) {
	//			let double = player.classList.contains('fullskin2') && lib.config.layout !== 'long2';
	//			const width = player.node.avatar.clientWidth;
	//			let w = width * (double ? 2 : 1);
	//			const bar = ui.create.div();
	//			bar.className = 'energy-bar';
	//			const isMobile = lib.device == 'android' || lib.device == 'ios';
	//			const heightMultiplier = isMobile ? 0.15 : 0.1;
	//			const topOffset = lib.config.extension_勇往直前_ywzq_ui_top != 0 ? lib.config.extension_勇往直前_ywzq_ui_top : isMobile ? 0.2 : 0.15;
	//			bar.style.cssText = `
	//                              z-index: 3;
	//                              width: ${w * 1.05}px;
	//                              height: ${w * heightMultiplier}px;
	//                              position: absolute;
	//                              top: ${w * -topOffset}px;
	//                              border: 2px solid rgba(0, 0, 0, 0.9);
	//                              border-radius: ${w * 0.05}px;
	//                              background: rgba(0, 0, 0, 0.6);
	//                              overflow: hidden;
	//                              box-sizing: border-box;
	//                              box-shadow: 0 0 5px rgba(0, 0, 0, 0.5);
	//                          `;
	//			bar.setNodeIntro(
	//				`
	//                              <div style="text-align:center">
	//                              <div style="font-size:1.2em">${player.ywzq.Name}</div>
	//                              <div style="font-size:0.7em; white-space:nowrap; color:${lib.config.menu_style == "wood" ? "888" : "#aaa"}">用于《勇往直前》扩展</div>
	//                              </div>
	//                              `,
	//				game.NpContent(player)
	//			);
	//			const fill = ui.create.div();
	//			fill.className = 'energy-fill';
	//			fill.style.cssText = `
	//                              width: 0%;
	//                              height: 100%;
	//                              position: absolute;
	//                              left: 0;
	//                              top: 0;
	//                              transition: all 0.8s cubic-bezier(0.22, 1, 0.36, 1);
	//                              opacity: 1;
	//                              background-size: 200% 100%;
	//                          `;
	//			const label = ui.create.div();
	//			label.className = 'energy-label';
	//			label.style.cssText = `
	//                              position: absolute;
	//                              width: 100%;
	//                              height: 100%;
	//                              display: flex;
	//                              align-items: center;
	//                              justify-content: center;
	//                              color: #ffffff;
	//                              font-size: ${w * 0.08}px;
	//                              font-weight: bold;
	//                              text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.8);
	//                              z-index: 1;
	//                          `;
	//			bar.appendChild(fill);
	//			bar.appendChild(label);
	//			player.appendChild(bar);
	//		}, player);
	//	},
	//	content() {
	//		'step 0'
	//		event.style = lib.config?.extension_勇往直前_ywzq_np || 1
	//		if (event.triggername == 'gameStart') {
	//			game.broadcastAll(function (player) {
	//				player.ywzq = {
	//					Np: player.ywzq?.Np || 0,
	//					Max: player.ywzq?.Max || 100,
	//					History: player.ywzq?.History || null,
	//					Gained: player.ywzq?.Gained || null,
	//					Lost: player.ywzq?.Lost || null,
	//					Enable: player.ywzq?.Enable ?? true,
	//					Skip: player.ywzq?.Skip || [],
	//					Name: player.ywzq?.Name || "灵气值",
	//					Color: player.ywzq?.Color || null
	//				}
	//			}, player);
	//			if (!player.ywzq.Enable) return;
	//			if (!player.hasSkill('subplayer')) {
	//				if (event.style == '1') {
	//					lib.skill._ywzq_np.create(player);
	//					player.updateMark("_ywzq_np");
	//					player.markSkill("_ywzq_np");
	//				}
	//				else if (event.style == '2') {
	//					player.updateMark("_ywzq_np");
	//					player.markSkill("_ywzq_np");
	//				}
	//			}
	//		}
	//		'step 1'
	//		if (event.triggername != 'np_change') {
	//			let change = 0;
	//			let reason = '';
	//			if (trigger && trigger.skill) {
	//				let skillName = get.translation(trigger.skill);
	//				skillName = skillName.includes('【') ? skillName : `【${skillName}】`;
	//				reason = `因${skillName}`;
	//			}
	//			else if (event.triggername == "gainBegin") {
	//				change = trigger.cards.length;
	//				let source = trigger.source || '系统';
	//				if (typeof source === 'object' && source.name) {
	//					source = get.translation(source.name);
	//				}
	//				reason += source === '系统' ? '获得牌' : `从${source}获得牌`;
	//			}
	//			else if (event.triggername == "phaseBeginStart") {
	//				change = 5;
	//				reason += '回合开始';
	//			}
	//			else if (event.triggername == "damageBegin") {
	//				change = trigger.num;
	//				if (player == trigger.source) {
	//					let target = trigger.player;
	//					reason += `对${get.translation(target.name)}造成伤害`;
	//				} else {
	//					let source = trigger.source;
	//					reason += source ? `受到${get.translation(source.name)}的伤害` : '受到伤害';
	//				}
	//			}
	//			else if (event.triggername == "useCardBegin") {
	//				change = 1;
	//				let cardName = get.translation(trigger.card.name);
	//				reason += `使用【${cardName}】`;
	//			}
	//			else if (event.triggername == "gameStart") {
	//				change = 15;
	//				reason += '游戏开始';
	//			}
	//			game.changeNp(player, change, reason);
	//			event.finish();
	//		} else {
	//			game.broadcastAll(function (player) {
	//				if (event.style == '1') {
	//					if (!player.ywzq.Enable) {
	//						player.querySelector('.energy-bar')?.delete()
	//						return
	//					};
	//					if (!player.querySelector('.energy-bar')) {
	//						player.unmarkSkill("_ywzq_np")
	//						lib.skill._ywzq_np.create(player)
	//					}
	//					let energy = player.ywzq.Np || 0;
	//					let maxEnergy = player.ywzq.Max || 100;
	//					const bar = player.querySelector('.energy-bar');
	//					if (!bar) return;
	//					const fill = bar.querySelector('.energy-fill');
	//					const label = bar.querySelector('.energy-label');
	//					if (fill && label) {
	//						let percentage = (energy / maxEnergy) * 100;
	//						fill.style.width = `${percentage >= 0 ? percentage : 0}%`;
	//						const gradient = player.ywzq?.Color || `${percentage <= 25 ?
	//							'linear-gradient(90deg, #1a5fb4 0%, #3584e4 50%, #62a0ea 100%, #1a5fb4 200%)' :
	//							percentage <= 50 ?
	//								'linear-gradient(90deg, #26a269 0%, #33d17a 50%, #8ff0a4 100%, #26a269 200%)' :
	//								percentage <= 75 ?
	//									'linear-gradient(90deg, #e66100 0%, #ffa348 50%, #ffbe6f 100%, #e66100 200%)' :
	//									'linear-gradient(90deg, #c01c28 0%, #ff7800 50%, #ffb380 100%, #c01c28 200%)'}`;
	//						fill.style.background = gradient;
	//						fill.style.boxShadow = `0 0 15px ${percentage <= 25 ? '#3584e4cc' :
	//							percentage <= 50 ? '#33d17acc' :
	//								percentage <= 75 ? '#ffa348cc' :
	//									'${lib.config.menu_style == "wood" ?  "#CC6600":"#ff7800"}cc'
	//							}`;
	//						label.innerHTML = `${Math.round(energy)}/${maxEnergy}`;
	//						label.style.textShadow = `0 0 8px ${percentage <= 25 ? '#3584e4' :
	//							percentage <= 50 ? '#33d17a' :
	//								percentage <= 75 ? '#ffa348' :
	//									'${lib.config.menu_style == "wood" ?  "#CC6600":"#ff7800"}'
	//							}`;
	//						bar.nodeContent = game.NpContent(player);
	//					}
	//				}
	//				else if (event.style == '2') {
	//					if (!player.ywzq.Enable) {
	//						player.unmarkSkill("_ywzq_np")
	//						return
	//					};
	//					if (player.querySelector('.energy-bar')) {
	//						player.querySelector('.energy-bar')?.delete()
	//					}
	//					player.updateMark("_ywzq_np");
	//				}
	//			}, player);
	//		}
	//	}
	//},
	sw_test: {
		trigger: {
			global: "phaseBefore",
			player: "enterGame",
		},
		filter(event, player) {
			return (event.name != "phase" || game.phaseNumber == 0);
		},
		direct: true,
		async content(event, trigger, player) {
			//game.zhu.die()
		}
	},
	//12星座守护神
	sw_zhanshenfangtianji_skill: {
		equipSkill: true,
		audio: ["fangtian"],
		trigger: { player: "useCard1" },
		forced: true,
		firstDo: true,
		filter(event, player) {
			if (event.card.name != "sha") return false;
			var card = event.card;
			var range;
			var select = get.copy(get.info(card).selectTarget);
			if (select == undefined) {
				if (get.info(card).filterTarget == undefined) return false;
				range = [1, 1];
			} else if (typeof select == "number") range = [select, select];
			else if (get.itemtype(select) == "select") range = select;
			else if (typeof select == "function") range = select(card, player);
			game.checkMod(card, player, range, "selectTarget", player);
			return range[1] != -1 && event.targets.length > range[1];
		},
		async content(event, trigger, player) {
			//TODO:技能提示
		},
		mod: {
			selectTarget(card, player, range) {
				if (card.name != "sha") return;
				if (range[1] == -1) return;
				var cards = player.getCards("h");
				if (!cards.length || cards.length > player.hp) return;
				//if (!cards.length) return;
				//for (var i = 0; i < cards.length; i++) {
				//	if (cards[i].classList.contains("selected") == false) return;
				//}
				range[1] += 2;
			},
		},
	},
	sw_zhangu: {
		charlotte: true,
		persevereSkill: true,
		unique: true,
		global: ["sw_zhangu_ban"],
		trigger: {
			global: "phaseBefore",
			player: "enterGame",
		},
		forced: true,
		init(player, skill) {
			if(player.name1 != "sw_xingshen_baiyang" && player.name2 != "sw_xingshen_baiyang") player.removeSkill(skill)
		},
		filter(event, player) {
			return (event.name != "phase" || game.phaseNumber == 0);
		},
		async content(event, trigger, player) {
			for (const ply of game.filterPlayer().sortBySeat(player)) {
				const card = await game.createCard2("sw_zhanshenfangtianji", "heart", 8);
				ply.$gain2(card, false);
				await game.delayx();
				ply.equip(card);

				var list = [];
				for (var i = 2; i < 6; i++) {
					for (var j = 0; j < ply.countEnabledSlot(i); j++) {
						list.push(i);
					}
				}
				ply.disableEquip(list);
			}
			
		},
		group: ["sw_zhangu_mianshang", "sw_zhangu_die"],
		subSkill: {
			ban: {
				charlotte: true,
				persevereSkill: true,
				trigger: {
					player: ["loseBefore", "disableEquipBefore"],
				},
				forced: true,
				filter(event, player) {
					if (event.name == "disableEquip") return event.slots.includes("equip1");
					var cards = player.getEquips("sw_zhanshenfangtianji");
					return event.cards.some(card => cards.includes(card));
				},
				content() {
					if (trigger.name == "lose") {
						trigger.cards.removeArray(player.getEquips("sw_zhanshenfangtianji"));
					} else {
						while (trigger.slots.includes("equip1")) trigger.slots.remove("equip1");
					}
				},
				mod: {
					canBeGained(card, source, player) {
						if (player.getEquips("sw_zhanshenfangtianji").includes(card)) return false;
					},
					canBeDiscarded(card, source, player) {
						if (player.getEquips("sw_zhanshenfangtianji").includes(card)) return false;
					},
					canBeReplaced(card, player) {
						if (player.getVEquips("sw_zhanshenfangtianji").includes(card)) return false;
					},
					cardname(card) {
						if (get.subtype(card, false) == "equip1") return "sha";
					},
					cardnature(card) {
						if (get.subtypes(card, false).includes("equip1")) return "kami";
					},
					cardDiscardable(card, player) {
						if (player.getEquips("sw_zhanshenfangtianji").includes(card)) return false;
					},
					cardEnabled2(card, player) {
						if (player.getEquips("sw_zhanshenfangtianji").includes(card)) return false;
					},
				},
				ai: {
					//这ai可太难写了，再说吧，反正一般不会有人机盟军
					/*
					effect: {
						player(card, player, target) {
							// 基础检查：卡牌无效或无目标时直接返回
							if (typeof card !== "object" || !target) return;
							//非实体牌直接返回
							if (!card.isCard) return;

							// 获取目标列表
							let targets = [],
								evt = _status.event.getParent("useCard");
							targets.addArray(ui.selected.targets);
							if (evt && evt.card == card) targets.addArray(evt.targets);

							// 修改点1：反转目标数量判断逻辑
							if (targets.length) {
								// 现在改为：如果是单目标就阻止（原先是多目标阻止）
								if (targets.length === 1) return "zeroplayertarget";
								return;
							}

							// 获取卡牌信息
							let info = get.info(card);
							if (!info || info.notarget || !info.filterTarget) return;

							// 处理目标选择范围
							let range,
								select = get.copy(info.selectTarget),
								filter;

							if (select === undefined) range = [1, 1];
							else if (typeof select === "number") range = [select, select];
							else if (get.itemtype(select) === "select") range = select;
							else if (typeof select === "function") range = select(card, player);

							if (info.singleCard) range = [1, 1];
							game.checkMod(card, player, range, "selectTarget", player);

							if (range[1] < -1) range = [1, 1];
							else if (range[0] < 0) {
								if (info.filterTarget === true) filter = game.players.length;
								else
									filter = game.countPlayer((current) => {
										return info.filterTarget(card, player, current);
									});
								range = [filter, filter];
							}

							if (!range) return;

							// 修改点2：反转范围判断逻辑
							// 现在改为：如果是单目标范围就阻止（原先是多目标阻止）
							if (range[0] === 1 && range[1] === 1) return "zeroplayertarget";

							return [1, 0, 0.7, 0];
						},
						// target(card, player, target) {
						// 	if(card.name != "sha") return;
						// 	// 基础态度
						// 	var att = get.attitude(player, target);
						// 	if(att > 0) return -1.2;  // 不选择友方
						// 	else return -1.5
						//
						// 	return -1;  // 默认价值
						// },
					},
					*/
				},
			},
			mianshang: {
				charlotte: true,
				persevereSkill: true,
				forced: true,
				trigger: { player: "damageBegin4" },
				filter(event, player) {
					return !(event.cards && event.cards.filterInD().length > 0) || !event.getParent().targets || event.getParent().targets.length <= 1;
				},
				content() {
					trigger.cancel();
				},
			},
			die: {
				charlotte: true,
				persevereSkill: true,
				forced: true,
				forceDie: true,
				trigger: { player: "die" },
				content() {
					for (const player of game.filterPlayer().sortBySeat(game.me)) {
						var list = [];
						for (var i = 1; i <= 5; i++) {
							for (var j = 0; j < player.countDisabledSlot(i); j++) {
								list.push("equip" + i);
							}
						}
						player.enableEquip(list);
					}

				}
			},
		},
	},
	sw_bansheng: {
		charlotte: true,
		persevereSkill: true,
		unique: true,
		direct: true,
		init(player, skill) {
			if (player.name1 != "sw_xingshen_baiyang" && player.name2 != "sw_xingshen_baiyang") player.removeSkill(skill)
		},
		filter(event, player){
			return !game.hasPlayer(function (current) {
				return current.name == "boss_taotie" || current.name2 == "boss_taotie";
			})
		},
		trigger: { player: 'phaseBegin' },
		async content(event, trigger, player) {
			await game.addNewPlayer("boss_taotie", 1)
		},
	},
	sw_wushuang: {
		audio: "wushuang",
		audioname2: { gz_lvlingqi: "wushuang_lvlingqi" },
		forced: true,
		locked: true,
		group: ["wushuang1", "wushuang2"],
		trigger: { player: "useCard1" },
		direct: true,
		filter(event, player) {
			if ((event.card.name != "juedou" && event.card.name != "sha") || !event.card.isCard) return false;
			if (event.targets) {
				if (
					game.hasPlayer(function (current) {
						return !event.targets.includes(current) && lib.filter.targetEnabled2(event.card, player, current);
					})
				) {
					return true;
				}
			}
			return false;
		},
		content() {
			"step 0";
			var num = game.countPlayer(function (current) {
				return !trigger.targets.includes(current) && lib.filter.targetEnabled2(trigger.card, player, current);
			});
			player
				.chooseTarget("无双：是否为" + get.translation(trigger.card) + "增加" + (num > 1 ? "至多两个" : "一个") + "目标？", [1, Math.min(2, num)], function (card, player, target) {
					var trigger = _status.event.getTrigger();
					var card = trigger.card;
					return !trigger.targets.includes(target) && lib.filter.targetEnabled2(card, player, target);
				})
				.set("ai", function (target) {
					var player = _status.event.player;
					var card = _status.event.getTrigger().card;
					return get.effect(target, card, player, player);
				})
			"step 1";
			if (result.bool) {
				if (player != game.me && !player.isOnline()) game.delayx();
			} else event.finish();
			"step 2";
			var targets = result.targets.sortBySeat();
			player.logSkill("sw_wushuang", targets);
			trigger.targets.addArray(targets);
		},
	},
	boss_xiongshou: {
		init(player, skill) {
			if (player.name1 != "boss_taotie" && player.name2 != "boss_taotie") player.removeSkill(skill)
		},
		group: ['boss_xiongshou_turn', 'boss_xiongshou_damage'],
		subSkill: {
			damage: {
				trigger: { source: 'damageBegin1' },
				forced: true,
				filter: function (event, player) {
					return event.notLink() && event.card && event.card.name == 'sha';
				},
				content: function () {
					trigger.num++;
				}
			},
			turn: {
				trigger: { player: 'turnOverBefore' },
				priority: 20,
				forced: true,
				filter: function (event, player) {
					return !player.isTurnedOver();
				},
				content: function () {
					trigger.cancel();
					game.log(player, '取消了翻面');
				},
			}
		},
		mod: {
			globalFrom: function (from, to, distance) {
				return distance - 1;
			}
		},
		ai: {
			noturn: true,
		}
	},
	boss_tanyu: {
		trigger: { player: 'phaseDiscardBefore' },
		forced: true,
		init(player, skill) {
			if (player.name1 != "boss_taotie" && player.name2 != "boss_taotie") player.removeSkill(skill)
		},
		content: function () {
			trigger.cancel();
		},
		group: 'boss_tanyu_hp',
		subSkill: {
			hp: {
				trigger: { player: 'phaseJieshuBegin' },
				forced: true,
				popup: false,
				filter: function (event, player) {
					return player.isMaxHandcard();
				},
				content: function () {
					player.loseHp();
				}
			}
		}
	},
	boss_cangmu: {
		init(player, skill) {
			if (player.name1 != "boss_taotie" && player.name2 != "boss_taotie") player.removeSkill(skill)
		},
		trigger: { player: 'phaseDrawBegin' },
		forced: true,
		content: function () {
			trigger.num += game.countPlayer() - 2;
		}
	},
	sw_weishen: {
		charlotte: true,
		persevereSkill: true,
		unique: true,
		//forced: true,
		init(player, skill) {
			if (player.name1 != "sw_xingshen_jinniu" && player.name2 != "sw_xingshen_jinniu") player.removeSkill(skill)
		},
		locked: true,
		trigger: {
			global: "phaseBefore",
			player: "enterGame",
		},
		filter(event, player) {
			return game.hasPlayer(current => current.identity == "fan") && (event.name != "phase" || game.phaseNumber == 0);
		},
		async cost(event, trigger, player) {
			const result = await player
				.chooseTarget("请选择【委身】的目标", lib.translate.sw_weishen_info, true, function (card, player, target) {
					return target != player && target.identity == "fan" && (!player.storage.sw_weishen2 || !player.storage.sw_weishen2.includes(target));
				})
				.set("ai", function (target) {
					//let att = get.attitude(_status.event.player, target);
					//if (att > 0) return att + 1;
					//if (att == 0) return Math.random();
					return Math.random();
				}).forResult();
			event.result = {
				bool: true,
				cost_data: result.targets[0],
			};
		},
		onremove(player) {
			if (!player.storage.sw_weishen2) return;
			game.countPlayer(function (current) {
				if (player.storage.sw_weishen2.includes(current) && current.hasSkill("sw_weishen_fujun")) {
					current.removeSkill("sw_weishen_fujun")
				}
			});
			delete player.storage.sw_weishen2;
		},
		async content(event, trigger, player) {
			let target = event.cost_data;
			if (!player.storage.sw_weishen2) player.storage.sw_weishen2 = [];
			player.storage.sw_weishen2.push(target);
			player.line(target)
			target.addSkill("sw_weishen_fujun");
			player.addSkill("sw_weishen_niangzi");
		},
		group: ["sw_weishen_fantan"],
		subSkill: {
			fujun: {
				charlotte: true,
				mark: true,
				marktext: "夫",
				intro: {
					name: "夫君",
					content: function (storage, player, skill) {
						return "你被坏女人盯上了！"
					},
				},
			},
			niangzi: {
				charlotte: true,
				mark: true,
				marktext: "娘",
				intro: {
					name: "娘子",
					content: function (storage, player, skill) {
						return "你被坏男人盯上了！"
					},
				},
			},
			fantan: {
				charlotte: true,
				persevereSkill: true,
				forced: true,
				trigger: { global: "damageBegin3" },
				audioname: ["daxiaoqiao", "re_xiaoqiao", "ol_xiaoqiao"],
				filter(event, player) {
					if (!event.player) return false
					if (event.player.hasSkill("sw_weishen_fujun") && game.filterPlayer(current => current.hasSkill("sw_weishen_niangzi")).length > 0) return true
					if (event.player.hasSkill("sw_weishen_niangzi") && game.filterPlayer(current => current.hasSkill("sw_weishen_fujun")).length > 0) return true
					return false
						
				},
				async content(event, trigger, player) {
					await game.delay(1)
					await player.popup("检定")
					await game.delay(2)
					let target = trigger.player
					let num = 0.2
					if (target.hasSkill("sw_weishen_niangzi")) {
						//不要打女人哦
						num += 0.2 * trigger.num
					}
					const yys = game.filterPlayer(function (current) {
						return [current.name1, current.name2].includes("sw_yuan") || [current.name1, current.name2].includes("sw_yang")
					})
					if(yys) num += 0.2 * yys.length
					if (Math.random() <= num) {
						player.popup("检定成功", "wood");
						if (target.hasSkill("sw_weishen_niangzi")) {
							trigger.player = game.filterPlayer(current => current.hasSkill("sw_weishen_fujun")).randomGet();//伤害转移大法
							await target.line(trigger.player)
						}
						if (target.hasSkill("sw_weishen_fujun")) {
							trigger.player = game.filterPlayer(current => current.hasSkill("sw_weishen_niangzi")).randomGet();//伤害转移大法
							await target.line(trigger.player)
						}
					}
					else {
						player.popup("检定失败", "fire");
					}
				},
				ai: {
					maixie_defend: true,
					effect: {
						target(card, player, target) {
							if (player.hasSkillTag("jueqing", false, target)) return;
							if (get.tag(card, "damage")) return 0.8;
						},
					},
					threaten: 1.3
				},
			},
		},
	},
	sw_zhaqu: {
		unique: true,
		forced: true,
		init(player, skill) {
			if (player.name1 != "sw_xingshen_jinniu" && player.name2 != "sw_xingshen_jinniu") player.removeSkill(skill)
		},
		filter(event, player) {
			return player.isDamaged();
		},
		trigger: { source: "damageSource" },
		async content(event, trigger, player) {
			player.recover(trigger.num)
			if (trigger.player.hasSkill("sw_weishen_fujun")) {
				await trigger.player.loseHp(trigger.num)
				player.recover(trigger.num)
			}
		},
	},
	sw_biyi_yuan: {
		init(player, skill) {
			if (player.name1 != "sw_yuan" && player.name2 != "sw_yuan") player.removeSkill(skill)
		},
		trigger: {
			global: "phaseBefore",
			player: "enterGame",
		},
		filter(event, player) {
			const suits = player.getStorage("sw_biyi_yuan");
			return suits.length < 4 && (event.name != "phase" || game.phaseNumber == 0);
		},
		forced: true,
		unique: true,
		async content(event, trigger, player) {
			player.addSkill("sw_weishen_fujun")
			const suits = lib.suit
				.filter(suit => {
					return !player.getStorage("sw_biyi_yuan")?.includes(suit);
				})
				.reverse();
			const result =
				suits.length > 1
					? await player
						.chooseControl(suits)
						.set("ai", () => {
							return get.event().controls.randomGet();
						})
						.set("prompt", "比翼：请记录一个花色")
						.forResult()
					: { control: suits[0] };
			const suit = result.control;
			if (suit) {
				player.markAuto("sw_biyi_yuan", [suit]);
				player.addTip("sw_biyi_yuan", get.translation("sw_biyi_yuan") + ' ' +player.getStorage("sw_biyi_yuan").reduce((str, suit) => str + get.translation(suit), ""));
			}
		},
		onremove(player, skill) {
			delete player.storage[skill];
			player.removeTip(skill);
		},
		intro: { content: "已记录$花色" },
		marktext: "翼",
		group: ["sw_biyi_yuan_get", "sw_biyi_yuan_die"],
		subSkill: {
			get: {
				trigger: { global: ["useCard", "respond"] },
				forced: true,
				filter(event, player) {
					if(!event.player || !event.player.hasSkill("sw_weishen_niangzi")) return false
					//if (!Array.isArray(event.respondTo)) return false;
					if (!event.card) return false;
					var suit = get.suit(event.card);
					if (suit == "none") return false;
					return player.getStorage("sw_biyi_yuan")?.includes(suit);
				},
				async content(event, trigger, player) {
					await player.draw(4)
					await player.recover()
				},
			},
			die: {
				trigger: { player: "dieAfter" },
				forceDie: true,
				forced: true,
				async content(event, trigger, player) {
					var targets = game.filterPlayer(current => current.identity == "fan");
					for (var target of targets) {
						target.addSkill("sw_biyi_yuan_ban");
						target.markAuto("sw_biyi_yuan_ban", player.getStorage("sw_biyi_yuan"));
					}
				},
			},
			ban: {
				onremove: true,
				charlotte: true,
				mod: {
					cardEnabled(card, player) {
						if (player.getStorage("sw_biyi_yuan_ban").includes(get.suit(card))) return false;
					},
					cardRespondable(card, player) {
						if (player.getStorage("sw_biyi_yuan_ban").includes(get.suit(card))) return false;
					},
					cardSavable(card, player) {
						if (player.getStorage("sw_biyi_yuan_ban").includes(get.suit(card))) return false;
					},
				},
				mark: true,
				marktext: "冤",
				intro: {
					content: "不能使用或打出$的牌",
				},
			},
		},
	},
	sw_biyi_yang: {
		init(player, skill) {
			if (player.name1 != "sw_yang" && player.name2 != "sw_yang") player.removeSkill(skill)
		},
		trigger: {
			global: "phaseBefore",
			player: "enterGame",
		},
		filter(event, player) {
			const nums = player.getStorage("sw_biyi_yang");
			return nums.length < 13 && (event.name != "phase" || game.phaseNumber == 0);
		},
		forced: true,
		unique: true,
		async content(event, trigger, player) {
			player.addSkill("sw_weishen_niangzi")
			const numbers = Array.from({ length: 13 }).map((_, i) => get.strNumber(i + 1))
				.filter(num => {
				return !player.getStorage("sw_biyi_yang")?.includes(num);
				});
			const result = await player
				.chooseButton(
					[
						"###" + get.prompt("sw_biyi_yang") + '###<div class="text center">选择' + parseFloat(Math.min(4, numbers.length)) + "个点数</div>",
						[numbers, "tdnodes"]
					],
					Math.min(4, numbers.length),
					true
				)
				.set("numbers", numbers)
				.set("ai", () => 1 + Math.random())
				.forResult();
			if (result.links) {
				const nums = result.links.sort((a, b) => {
					return get.numString(a) - get.numString(b);
				});
				player.markAuto("sw_biyi_yang", nums);
				player.addTip("sw_biyi_yang", get.translation("sw_biyi_yang") + player.getStorage("sw_biyi_yang").reduce((str, num) => str + ' ' + num, ""));
			}
			
		},
		onremove(player, skill) {
			delete player.storage[skill];
			player.removeTip(skill);
		},
		intro: { content: "已记录$点数" },
		marktext: "翼",
		group: ["sw_biyi_yang_get", "sw_biyi_yang_die"],
		subSkill: {
			get: {
				trigger: { global: ["useCard", "respond"] },
				forced: true,
				filter(event, player) {
					//debugger
					if (!event.player || !event.player.hasSkill("sw_weishen_fujun")) return false
					//if (!Array.isArray(event.respondTo)) return false;
					if (!event.card) return false;
					var num = get.number(event.card);
					if (num == "none" || num == "0") return false;
					return player.getStorage("sw_biyi_yang")?.includes(get.strNumber(num));
				},
				async content(event, trigger, player) {
					await player.draw(4)
					await player.recover()
				},
			},
			die: {
				trigger: { player: "dieAfter" },
				forceDie: true,
				forced: true,
				async content(event, trigger, player) {
					var targets = game.filterPlayer(current => current.identity == "fan");
					for (var target of targets) {
						target.addSkill("sw_biyi_yang_ban");
						target.markAuto("sw_biyi_yang_ban", player.getStorage("sw_biyi_yang"));
					}
				},
			},
			ban: {
				onremove: true,
				charlotte: true,
				mod: {
					cardEnabled(card, player) {
						if (player.getStorage("sw_biyi_yang_ban").includes(get.strNumber(get.number(card)))) return false;
					},
					cardRespondable(card, player) {
						if (player.getStorage("sw_biyi_yang_ban").includes(get.strNumber(get.number(card)))) return false;
					},
					cardSavable(card, player) {
						if (player.getStorage("sw_biyi_yang_ban").includes(get.strNumber(get.number(card)))) return false;
					},
				},
				mark: true,
				marktext: "冤",
				intro: {
					content: "不能使用或打出$点数的牌",
				},
			},
		},
	},
	sw_lingxi: {
		charlotte: true,
		persevereSkill: true,
		unique: true,
		forced: true,
		init(player, skill) {
			if (player.name1 != "sw_xingshen_shuangzi" && player.name2 != "sw_xingshen_shuangzi") player.removeSkill(skill)
			else {
				player.storage[skill] = false
			}
		},
		filter(event, player) {
			return game.hasPlayer(function (current) {
				return [current.name1, current.name2].includes("sw_castor") || [current.name1, current.name2].includes("sw_pollux")
			})
		},
		onremove(player, skill) {
			delete player.storage[skill];
		},
		trigger: { player: 'dieBegin' },
		async content(event, trigger, player) {
			const targets = game.filterPlayer(function (current) {
				return ([current.name1, current.name2].includes("sw_castor") || [current.name1, current.name2].includes("sw_pollux")) && current.getHp() > 0
			})
			if(!player.storage.sw_lingxi) {
				//首次进入
				player.storage.sw_lingxi = true
				for(let target of targets) {
					if(target.hasSkill("sw_tongxin")){
						game.broadcastAll((player) => {
							player.storage.sw_tongxin = true
						}, target)
						target.popup("修改", "fire")
					}
				}
			}
			const target = targets.randomGet()
			if(target){
				trigger.cancel();
				player.line(target)
				const delt = player.getHp(true) - target.getHp()
				if (delt != 0) {
					const next = player.changeHp(-delt);
					next._triggered = null;
					await next;
				}
				await game.delay(2)
			}
		},
		ai: {
			threaten: 1.5,
		},
	},
	sw_zhuoxin: {
		charlotte: true,
		persevereSkill: true,
		unique: true,
		forced: true,
		init(player, skill) {
			if (player.name1 != "sw_xingshen_shuangzi" && player.name2 != "sw_xingshen_shuangzi") player.removeSkill(skill)
			else {
				player.storage[skill] = ["guicai", "fankui", "sbjizhi", "dczhiheng", "jilue_wansha", "boss_jiang", "reguhuo"]
			}
		},
		onremove(player, skill) {
			delete player.storage[skill];
		},
		filter(event, player) {
			return game.hasPlayer(function (current) {
				return [current.name1, current.name2].includes("sw_castor") || [current.name1, current.name2].includes("sw_pollux")
			})
		},
		trigger: { player: 'phaseBegin' },
		async content(event, trigger, player) {
			const targets = game.filterPlayer(function (current) {
				return ([current.name1, current.name2].includes("sw_castor") || [current.name1, current.name2].includes("sw_pollux"))
			})
			for(let target of targets) await target.loseMaxHp(1)
			if(player.storage.sw_zhuoxin) {
				const skill = player.storage.sw_zhuoxin.randomRemove()
				player.addSkill(skill);
			}

		}
	},
	sw_tongxin: {
		charlotte: true,
		persevereSkill: true,
		unique: true,
		forced: true,
		init(player, skill) {
			if (![player.name1, player.name2].some(val => ["sw_castor", "sw_pollux"].includes(val))) player.removeSkill(skill)
			else player.storage[skill] = false
		},
		// onremove(player, skill) {
		// 	delete player.storage[skill];
		// },
		filter(event, player) {
			return event.player && event.player != player && [event.player.name1, event.player.name2].some(val => ["sw_castor", "sw_pollux"].includes(val))
		},
		trigger: { global: "changeHpEnd" },
		async content(event, trigger, player) {
			const target = trigger.player
			const delt = player.getHp(true) - target.getHp()
			if (delt != 0) {
				player.line(target)
				const next = player.changeHp(-delt);
				next._triggered = null;
				await next;
				await game.delay(2.5)
				if(delt > 0) {
					//体力减少
					if(player.storage.sw_tongxin) await player.draw(4)
					else await player.recover()
				}
				else {
					await player.draw(2)
				}
			}
		},
		ai: {
			maixie: true,
			maixie_defend: true,
			effect: {
				target(card, player, target) {
					if (!get.tag(card, "damage")) return;
					var num = get.tag(card, "damage");
					if (
						target.hp <= 1 ||
						(player.hasSkillTag("damageBonus", false, {
								target: target,
								card: card,
							}) &&
							!target.hasSkillTag("filterDamage", null, {
								player: player,
								card: card,
							}))
					)
						return [1, -0.5];
					else if(num > 1) {
						if (get.attitude(player, target) > 0) {
							return [1, 1.5];
						}
						else return 1;
					}
					else return [1, 2];
				},
			},
		},
		group: ["sw_tongxin_die"],
		subSkill: {
			die: {
				charlotte: true,
				persevereSkill: true,
				unique: true,
				forced: true,
				trigger: { global: "dieAfter" },
				filter(event, player) {
					return event.player && event.player != player && [event.player.name1, event.player.name2].some(val => ["sw_castor", "sw_pollux"].includes(val))
				},
				async content(event, trigger, player) {
					await player.die()
				},
			},
		},
	},
	sw_tianlei: {
		charlotte: true,
		persevereSkill: true,
		unique: true,
		forced: true,
		init(player, skill) {
			if (![player.name1, player.name2].some(val => ["sw_xingshen_sheshou"].includes(val))) player.removeSkill(skill)
		},
		onremove(player, skill) {
			game.filterPlayer(function(current) {
				return current.identity == "fan"
			}, [], true).forEach(function(player) {
				player.removeSkill("sw_tianlei_num")
			})
		},
		filter(event, player) {
			if(!event.player || event.player.identity != "fan") return false
			const num = get.number(event.card, event.player)
			if(num == "unsure" || num == null) return false
			return !event.player.hasSkill("sw_tianlei_num") || num != event.player.countMark("sw_tianlei_num")
		},
		trigger: { global: ["useCard", "respond"] },
		async content(event, trigger, player) {
			const target = trigger.player
			const num = get.number(trigger.card, trigger.player)
			if(target.hasSkill("sw_tianlei_num") && target.countMark("sw_tianlei_num") > 0) {
				if(target.countMark("sw_tianlei_num") > num) {
					// 虚拟闪电判定
					await game.delayx(2.5)
					await target.executeDelayCardEffect("shandian")
				}
				else {
					target.setMark("sw_tianlei_num", num, false)
					target.addTip("sw_tianlei_num", `天雷 ${num}`);
				}
			}
			else {
				target.addTempSkill("sw_tianlei_num")
				target.setMark("sw_tianlei_num", num, false)
				target.addTip("sw_tianlei_num", `天雷 ${num}`);
			}
		},
		//TODO: 好吧，AI挺难写的
		ai: {

		},
	},
	sw_tianlei_num: {
		charlotte: true,
		silent: true,
		onremove(player, skill) {
			//player.clearMark("sw_tianlei_num", false)
			delete player.storage.sw_tianlei_num
			player.removeTip("sw_tianlei_num")
		},
		mark: true,
		marktext: "雷",
		intro: {
			name: "天雷",
			name2: "雷",
			content: "本回合内使用点数小于$的牌时进行一次虚拟闪电判定",
			// content(storage, player) {
			// 	if (!storage) return "";
			// 	return "";
			// },
		},
		group: "sw_tianlei_num_die",
		subSkill: {
			die: {
				trigger: { player: "dieBegin" },
				silent: true,
				sourceSkill: "sw_tianlei_num",
				filter(event, player) {
					return event.player == player && player.hasSkill("sw_tianlei_num")
				},
				content() {
					player.removeSkill("sw_tianlei_num")
				},
			},
		},
	},




	//结束
	sw_bingluan: {
		trigger: {
			player: "useCardAfter",
		},
		charlotte: true,
		persevereSkill: true,
		unique: true,
		init(player, skill) {
			if (player.name1 != "boss_jiaxu" && player.name2 != "boss_jiaxu") player.removeSkill(skill)
		},
		filter(event, player) {
			if (!get.tag(event.card, "damage")) return false;
			return true;
		},
		async cost(event, trigger, player) {
			event.result = await player
				.chooseTarget(get.prompt("sw_bingluan"), `令一名其他角色对另一名角色使用一张【杀】，否则前者失去1点体力且你回复1点体力`)
				.set("filterTarget", (card, player, target) => {
					if (!ui.selected.targets.length) return target != player;
					return ui.selected.targets[0].canUse({ name: "sha" }, target, true);
				})
				.set("selectTarget", 2)
				.set("multitarget", true)
				.set('complexTarget', true)
				.set('complexSelect', true)
				.set("targetprompt", ["出杀", "被打"])
				.set("ai", target => {
					const player = get.player();
					if (!ui.selected.targets.length) {
						return get.effect(target, { name: "losehp" }, player);
					}
					else {
						const [targetx] = ui.selected.targets;
						if (targetx.canUse({ name: "sha" }, target, true)) {
							return get.effect(target, { name: "sha" }, targetx, player)
						}
						return 100 - get.attitude(player, target);
					}
				})
				.forResult();
		},
		async content(event, trigger, player) {
			const [user, target] = event.targets;
			const result = await user.chooseToUse(function (card, player, event) {
				if (get.name(card) != "sha") return false;
				return lib.filter.filterCard.apply(this, arguments);
			}, "兵乱：对" + get.translation(target) + "使用一张杀，或失去1点体力")
				.set("targetRequired", true)
				.set("complexSelect", true)
				.set("filterTarget", function (card, player, target) {
					if (target != get.event().sourcex && !ui.selected.targets.includes(get.event().sourcex)) return false;
					return lib.filter.filterTarget.apply(this, arguments);
				})
				.set("sourcex", target)
				.forResult();
			if (!result.bool) {
				await user.loseHp();
				await player.recover();
			}
		},
		ai: {
			expose: 0.5,
		},
	},
	sw_moao: {
		trigger: {
			player: "dieBegin",
		},
		charlotte: true,
		persevereSkill: true,
		unique: true,
		forced: true,
		init(player, skill) {
			if (player.name1 != "boss_jiaxu" && player.name2 != "boss_jiaxu") player.removeSkill(skill)
		},
		filter(event, player) {
			return game.hasPlayer(function (current) {
				return [current.name1, current.name2].includes("sw_sangshi")
			})
		},
		async content(event, trigger, player) {
			const targets = game.filterPlayer(function (current) {
				return [current.name1, current.name2].includes("sw_sangshi") && current.getHp() > 0
			})
			const target = targets.randomGet()
			if(target){
				trigger.cancel();
				player.line(target)
				const delt = player.getHp(true) - target.getHp()
				if (delt != 0) {
					const next = player.changeHp(-delt);
					next._triggered = null;
					await next;
				}
				await game.delay(2)
				await target.die()
			}
		},
	},
	sw_chuce: {
		enable: "chooseToUse",
		filter(event, player) {
			if (!_status.connectMode && !player.countCards("hs", card => get.type2(card) == "trick") || !player.countCards("hs")) return false;
			for (let i of lib.inpile) {
				let type = get.type2(i);
				if ((type == "basic" || type == "trick") && event.filterCard({ name: i }, player, event)) return true;
			}
			return false;
		},
		unique: true,
		init(player, skill) {
			if (player.name1 != "boss_jiaxu" && player.name2 != "boss_jiaxu") player.removeSkill(skill)
		},
		group: "sw_chuce_immune",
		chooseButton: {
			dialog(event, player) {
				let dialog = ui.create.dialog("出策", "hidden");
				let list = [], type;
				for (let name of lib.inpile) {
					if (name == "sha") {
						if (event.filterCard({ name: name }, player, event)) list.push(["基本", "", "sha"]);
						for (let j of lib.inpile_nature) {
							if (event.filterCard({ name: name, nature: j }, player, event)) list.push(["基本", "", "sha", j]);
						}
					}
					else if (get.type2(name) == "trick" && event.filterCard({ name: name }, player, event)) list.push(["锦囊", "", name]);
					else if (get.type(name) == "basic" && event.filterCard({ name: name }, player, event)) list.push(["基本", "", name]);
				}
				dialog.add([list, "vcard"]);
				return dialog;
			},
			filter(button, player) {
				return _status.event.getParent().filterCard({ name: button.link[2], storage: { sw_chuce: true } }, player, _status.event.getParent());
			},
			check(button) {
				let player = get.player();
				return player.getUseValue({ name: button.link[2], storage: { sw_chuce: true } });
			},
			backup(links, player) {
				return {
					check(card) {
						return 8 - get.value(card);
					},
					position: "hs",
					filterCard: card => get.type2(card) === "trick",
					viewAs: {
						name: links[0][2],
						nature: links[0][3],
						storage: {
							sw_chuce: true,
						},
					},
					precontent() {
						player.addTempSkill("sw_chuce_effect");
					},
				}
			},
			prompt(links, player) {
				return `将一张锦囊牌当${(get.translation(links[0][3]) || "")}【${get.translation(links[0][2])}】使用`;
			}
		},
		hiddenCard(player, name) {
			let type = get.type2(name);
			return (type == "basic" || type == "trick") && (_status.connectMode || player.countCards("hs", card => get.type2(card) == "trick"));
		},
		ai: {
			save: true,
			fireAttack: true,
			respondSha: true,
			respondShan: true,
			skillTagFilter(player) {
				if (!player.countCards("hs")) return false;
			},
			order: 1,
			result: {
				player(player) {
					if (get.event().dying) return get.attitude(player, get.event().dying);
					return 1;
				},
			},
		},
		mod: {
			targetInRange(card, player, target) {
				if (card?.storage?.sw_chuce) return true;
			},
			cardUsable(card, player) {
				if (card?.storage?.sw_chuce) return true;
			},
		},
		subSkill: {
			effect: {
				trigger: { player: "useCard" },
				forced: true,
				charlotte: true,
				silent: true,
				filter(event, player) {
					if (event.skill != "sw_chuce_backup") return false;
					return true;
				},
				content() {
					if (trigger.addCount !== false) {
						trigger.addCount = false;
						const stat = trigger.player.getStat().card, name = trigger.card.name;
						if (typeof stat[name] == "number") stat[name]--;
					}
				},
			},
			used: {},
			backup: {},
			immune: {
				trigger: {
					global: "useCard",
				},
				filter(event, player) {
					return get.type2(event.card) == "trick" && event.player != player;
				},
				logTarget: "player",
				prompt2(event, player) {
					return `令${get.translation(event.card)}无效，你摸三张牌，然后你可以视为使用之`;
				},
				check(event, player) {
					return -get.sgnAttitude(player, event.player) * event.player.getUseValue(event.card) >= -5;
				},
				async content(event, trigger, player) {
					await player.draw(3);
					trigger.targets.length = 0;
					trigger.all_excluded = true;
					const ncard = new lib.element.VCard({ name: trigger.card.name, nature: trigger.card.nature });
					if (player.hasUseTarget(ncard) && get.type(ncard) != "delay") {
						await player.chooseUseTarget(`出策：是否视为使用${get.translation(ncard)}？`, ncard);
					}
				},
			},
		}
	},
	sw_shimu: {
		charlotte: true,
		persevereSkill: true,
		unique: true,
		forced: true,
		init(player, skill) {
			if (player.name1 != "boss_jiaxu" && player.name2 != "boss_jiaxu") player.removeSkill(skill)
		},
		trigger: {
			global: "recoverBegin",
			target: "useCardToTarget",
		},
		global: "sw_shimu_ai",
		group: "sw_shimu_zombify",
		filter(event, player) {
			if (player != _status.currentPhase) return false;
			if (event.name == "recover") return event.player != player;
			return get.type2(event.card) == "trick";
		},
		async content(event, trigger, player) {
			if (trigger.name == "recover") {
				trigger.cancel();
			} else {
				trigger.getParent().excluded.add(player);
			}
		},
		subSkill: {
			ai: {
				ai: {
					effect: {
						target(card, player, target) {
							if (_status.currentPhase == target && _status.currentPhase?.hasSkill("sw_shimu") && get.tag(card, "recover")) return "zeroplayertarget";
						},
					},
				},
			},
			zombify: {
				trigger: {
					global: "dieAfter",
				},
				filter(event, player) {
					return ![event.player.name1, event.player.name2].includes("sw_sangshi")
				},
				logTarget: "player",
				charlotte: true,
				persevereSkill: true,
				unique: true,
				forced: true,
				async content(event, trigger, player) {
					await game.addNewPlayer("sw_sangshi")
				},
			},
		},
	},
	sw_ganran: {
		trigger: {
			global: "phaseJieshuBegin",
		},
		init(player, skill) {
			if (player.name1 != "sw_sangshi" && player.name2 != "sw_sangshi") player.removeSkill(skill)
		},
		filter(event, player) {
			return player.getStat("damage") > 0;
		},
		forced: true,
		locked: false,
		async content(event, trigger, player) {
			const num = player.getDamagedHp();
			await player.recover(num);
			await player.draw(num);
		},
	},
	sw_xiaohui: {
		trigger: {
			player: "phaseJieshuBegin",
		},
		init(player, skill) {
			if (player.name1 != "sw_pingmin" && player.name2 != "sw_pingmin") player.removeSkill(skill)
		},
		forced: true,
		locked: false,
		async content(event, trigger, player) {
			//给盟军打钱！
		},
		ai: {
			effect: {
				target(card, player, target) {
					if (get.tag(card, "recover")) return "zeroplayertarget";
				},
			},
		},
	},
	sw_danxiao: {
		global: "sw_danxiao_1",
		locked: true,
		init(player, skill) {
			if (player.name1 != "sw_pingmin" && player.name2 != "sw_pingmin") player.removeSkill(skill)
		},
		subSkill: {
			1: {
				mod: {
					cardSavable(card, player, target) {
						if (card.name == "tao" && target != player && target.hasSkill("sw_danxiao")) return false;
					},
				},
			},
		}
	},
	sw_shibian: {
		trigger: {
			player: "die",
		},
		init(player, skill) {
			if (player.name1 != "sw_sangshi" && player.name2 != "sw_sangshi") player.removeSkill(skill)
		},
		forced: true,
		locked: false,
		async content(event, trigger, player) {
			//暂时没用
		},
	},
	sw_huisheng: {
		enable: 'chooseToUse',
		mark: true,
		persevereSkill: true,
		skillAnimation: true,
		limited: true,
		animationColor: 'orange',
		filter: function (event, player) {
			if (event.type == 'dying') {
				if (player != event.dying) return false;
				return true;
			}
			return false;
		},
		content: function () {
			'step 0'
			player.awakenSkill('sw_huisheng');
			player.discard(player.getCards('hej'));
			'step 1'
			player.link(false);
			player.turnOver(false);
			'step 2'
			player.draw(3);
			if (player.hp < 3) player.recover(3 - player.hp);
		},
		ai: {
			order: 1,
			skillTagFilter: function (player, arg, target) {
				if (player != target || player.storage.wechatniepan) return false;
			},
			save: true,
			result: {
				player: function (player) {
					if (player.hp <= 0) return 10;
					if (player.hp <= 2 && player.countCards('he') <= 1) return 10;
					return 0;
				}
			},
			threaten: 0.6,
		},
	},
	_sw_playerLimit: {
		ruleSkill: true,
		forced: true,
		trigger: {
			player: "gainMaxHpBefore",
		},
		filter: function (event, player) {
			return player.identity == "fan" && event.num == Infinity;
		},
		async content(event, trigger, player) {
			trigger.num = 1;
			//if (trigger.num == Infinity) 
		},
		group: ["_sw_playerLimit_discard"],
		subSkill: {
			discard: {
				ruleSkill: true,
				trigger: { player: "gainAfter" },
				forced: true,
				filter: function (event, player) {
					return player.countCards("h") > 150 && player.identity == "fan";
				},
				async content(event, trigger, player) {
					let target = trigger.player;
					const cardx = target.getDiscardableCards(target, "h");
					const num = player.countCards("h") - 150;
					if (cardx.length) {
						let cardsToDis = cardx.randomGets(num)
						target.lose(cardsToDis)._triggered = null;
						game.log(target, "弃置了", cardsToDis);
						target.$throw(cardsToDis);
					}
				},
			},
		},
	},
	_sw_zhuLimit: {
		ruleSkill: true,
		trigger: { player: 'drawBefore' },
		lastDo: true,
		forced: true,
		//forceDie: true,
		filter: function (event, player) {
			//console.log(event);
			return event.num > 20 && player == game.zhu;
		},
		async content(event, trigger, player) {
			trigger.num = 20;
		},
		group: ["_sw_zhuLimit_discard"],//, "_sw_zhuLimit_changeCharacter"
		subSkill: {
			discard: {
				ruleSkill: true,
				trigger: { player: "gainAfter" },
				forced: true,
				filter: function (event, player) {
					return player.countCards("h") > 100 && player == game.zhu;
				},
				async content(event, trigger, player) {
					const result = await player.chooseCard(`请弃置${player.countCards("h") - 100}张牌`, "h", player.countCards("h") - 100, true)
						.set("ai", card => {
							return 8 - get.value(card);
						})
						.forResult();
					//console.log(result);
					//var next = player.chooseToDiscard("h", player.countCards("h") - 10, true);
					player.lose(result.cards)._triggered = null;
					game.log(player, "弃置了", result.cards);
					player.$throw(result.cards);
				},
			},
			// changeCharacter: {
			// 	trigger: { player: 'changeCharacter' },
			// 	ruleSkill: true,
			// 	forced: true,
			// 	filter: function (event, player) {
			// 		return player == game.zhu;
			// 	},
			// 	async content(event, trigger, player) {
			// 		trigger.cancel()
			// 		player.chat("孩子们，我是不会换的")
			// 	}
			// },
		},
	},
	// _sw_zhuDie: {
	// 	trigger: { player: "die" },
	// 	forced: true,
	// 	forceDie: true,
	// 	lastDo: true,
	// 	ruleSkill: true,
	// 	filter: function (event, player) {
	// 		return player == game.zhu;
	// 	},
	// 	async content(event, trigger, player) {
	// 		console.log("主公死亡");
	// 		debugger
	// 	},
	// },
	sw_getSkill: {

		//trigger: { source: "damageEnd" },
		//forced: true,
		//popup: false,
		//filter: function (event, player) {
		//	return event.player == player._toKill;
		//},
		//content: function () {
		//	game.log(player, "对击杀目标造成了伤害");
		//	player.changeLingli(trigger.num);
		//},


		locked: true,
		forced: true,
		priority: -100,
		superCharlotte: true,
		charlotte: true,
		ruleSkill: true,
		popup: false,
		trigger: {
			player: "damageEnd",
			source: "damageSource",
		},
		//filter: function (event, player) {
		//	return player.hasMark("sw_getSkill") && player.countMark("sw_getSkill") % 3 == 0;
		//},
		init: function (player) {
			if (!player.storage.sw_getSkillName) player.storage.sw_getSkillName = [];
			if (!player.storage.sw_getSkillMaxcnt) player.storage.sw_getSkillMaxcnt = lib.configOL.hemengaozhan_startNum ? parseInt(lib.configOL.hemengaozhan_startNum) : 3;
			player.updateMarks();
		},
		content: function () {
			"step 0";
			if (!player.storage.sw_getSkillName) player.storage.sw_getSkillName = [];
			if (!player.storage.sw_getSkillMaxcnt) player.storage.sw_getSkillMaxcnt = lib.configOL.hemengaozhan_startNum ? parseInt(lib.configOL.hemengaozhan_startNum) : 3;

			player.addMark("sw_getSkill", Math.min(trigger.num, 20));
			if (player.countMark("sw_getSkill") >= 4) {
				event.goto(1);
			}
			else event.finish();
			"step 1";
			list = game.getSWSkillsList(player, lib.configOL.hemengaozhan_allSkills)
				.filter(function (i) {
					return !player.hasSkill(i, null, null, false);
				})
				.randomGets(5);
			if (list.length == 0) game.log(player, "没有技能可选");
			else {
				event.videoId = lib.status.videoId++;
				game.broadcastAll((skills, id) => {
					var dialog = ui.create.dialog("forcebutton");
					dialog.videoId = id;
					dialog.add("选择一个技能获得");
					for (var i = 0; i < skills.length; i++) {
						dialog.add('<div class="popup pointerdiv" style="width:80%;display:inline-block"><div class="skill">【' + get.translation(skills[i]) + "】</div><div>" + lib.translate[skills[i] + "_info"] + "</div></div>");
					}
					dialog.addText(" <br> ");
				}, list, event.videoId);

				player.chooseControl(list);
			}
			"step 2";
			game.broadcastAll("closeDialog", event.videoId);
			player.addSkills(result.control);
			player.storage.sw_getSkillName.push(result.control);
			player.removeMark("sw_getSkill", 4);
			"step 3";
			if (player.countMark("sw_getSkill") >= 4) {
				event.goto(1);
			}
			"step 4";
			var skills = player.getSkills(null, false, false).filter(function (i) {
				if (i == "sw_getSkill") return false;
				var info = get.info(i);
				return info && !info.charlotte;
			});
			event.skills = skills;

			player.storage.sw_getSkillName = player.storage.sw_getSkillName.filter(skill =>
				skills.includes(skill)
			);

			if (player.storage.sw_getSkillMaxcnt >= player.storage.sw_getSkillName.length) event.finish();
			else event.goto(5);
			"step 5";
			var skills = player.storage.sw_getSkillName.slice().reverse();
			var list = [];
			for (var skill of skills) {
				list.push([skill, '<div class="popup text" style="width:calc(100% - 10px);display:inline-block"><div class="skill">【' + get.translation(skill) + "】</div><div>" + lib.translate[skill + "_info"] + "</div></div>"]);
			}
			var num = player.storage.sw_getSkillName.length - player.storage.sw_getSkillMaxcnt;
			var next = player.chooseButton([`请选择失去` + get.cnNumber(num) + `个技能`, [list, "textbutton"]])
				.set("forced", true)
				.set("selectButton", num)
				.set('complexSelect', false)
				.set("skills", skills);
			"step 6";
			if (result.bool) {
				var skills = result.links;
				player.removeSkills(skills.slice(0));
			}
			"step 7";
			var sks = player.getSkills(null, false, false).filter(function (i) {
				if (i == "sw_getSkill") return false;
				var info = get.info(i);
				return info && !info.charlotte;
			});

			player.storage.sw_getSkillName = player.storage.sw_getSkillName.filter(skill =>
				sks.includes(skill)
			);
			player.checkMarks();
		},
		mark: true,
		marktext: "灵",
		intro: {
			name: "灵气",
			content: function (storage, player) {
				if (!player.storage.sw_getSkillName) player.storage.sw_getSkillName = [];
				if (!player.storage.sw_getSkillMaxcnt) player.storage.sw_getSkillMaxcnt = 3;
				return `灵气值：` + player.countMark("sw_getSkill") + `<br><li>每当你造成或受到伤害时，你获得等同于伤害量的灵气值，若此时当灵气值大于等于4，你令系统随机检索五个技能，你选择其一获得之并失去四点灵气。<br><li>单次获取灵气值最多为20点。<br><li>你通过此法获得的技能数：` + player.storage.sw_getSkillName.length + "/" + player.storage.sw_getSkillMaxcnt;
			},
		},
	},
	sw_bossGetSkill2: {
		forced: true,
		charlotte: true,
		popup: false,
		trigger: {
			player: ["phaseZhunbeiBegin"],
		},
		//filter: function (event, player, name) {
		//	return !player.storage.sw_bossGetSkill;
		//},
		content: function () {
			list = game.getSWSkillsList(player, lib.configOL.hemengaozhan_allSkills)
				.filter(function (i) {
					return !player.hasSkill(i, null, null, false);
				})
				.randomGets(2);
			player.addSkills(list);
		},
	},
	sw_xionge: {
		charlotte: true,
		forced: true,
		silent: true,
		direct: true,
		trigger: { player: "phaseDrawBegin2" },
		filter(event, player) {
			return !event.numFixed;
		},
		content: function () {
			trigger.num += Math.floor(get.gameInfo(0) / 2);
		},
		mod: {
			cardUsable: function (card, player, num) {
				if (card.name == "sha") return num + Math.floor(get.gameInfo(0) / 3);
			},
		},
		//mark: true,
		//direct: true,
		//marktext: "恶",
		//intro: {
		//	name: "凶恶",
		//	content(storage, player) {
		//		return `<li>摸牌阶段额外摸${Math.floor(_status.killNum[0] / 2)}张牌<br><li>出【杀】次数+${Math.floor(_status.killNum[0] / 3)}`;
		//	},
		//},
	},
	sw_getHuihe: {
		charlotte: true,
		forced: true,
		silent: true,
		popup: false,
		nopop: true,
		trigger: {
			global: "phaseJieshuBegin",
		},
		filter: function (event, player) {
			return event.player != undefined && event.player.identity == "fan";
		},
		content: function () {
			"step 0";
			//if (trigger.player.identity != "fan") event.finish();
			player.addMark("sw_getHuihe", 1, false);
			if (player.countMark("sw_getHuihe") < 5) {
				event.finish();
			}
			"step 1";
			player.removeMark("sw_getHuihe", player.countMark("sw_getHuihe"), false);
			player.insertPhase();
			player.logSkill("sw_getHuihe");
		},
		mark: true,
		marktext: "额",
		intro: {
			name: "额外回合",
			content: function (storage, player) {
				return `已经经过了：` + player.countMark("sw_getHuihe") + `回合，达到5时获得额外回合。`;
			},
		},
	},
	_sw_viewTeamHand: {
		forced: true,
		silent: true,
		ai: {
			viewHandcard: true,
			skillTagFilter(player, tag, target) {
				if (!target || !player || player == target || target.identity != "fan") return false;
			},
		},
	},

	sw_chest: {
		trigger: { player: "damage" },
		forced: true,
		persevereSkill: true,
		logTarget: "source",
		filter: function (event, player) {
			return event.source != undefined && player.countCards("hej") > 0 && player.identity == "nei";
		},
		content: function () {
			"step 0";
			player.draw();
			"step 1";
			var cards = player.getCards("hej");
			cards.randomSort();
			cards = cards.slice(0, trigger.num);
			trigger.source.gain("give", cards, player);
			//console.log(event.name);
			//player.addSkill("sw_test2");
			//trigger.source.addSkill("sw_test2");
		},
		group: ["sw_chest_jump"],
		subSkill: {
			jump: {
				filter: function (event, player) {
					return player.identity == "nei";
				},
				mod: {
					cardEnabled2(card, player) {
						if (player.identity == "nei" && get.position(card) == "h") return false;
					},
				},
				persevereSkill: true,
				popup: false,
				trigger: {
					player: ["phaseUseBefore", "phaseDiscardBefore"],
				},
				forced: true,
				content: function () {
					trigger.cancel();
				},
			},
		},
	},


	sw_chestsilver: {
		trigger: { player: "die" },
		filter: function (event, player) {
			return event.source && event.source.isIn() && event.source.identity == "fan" && player.identity == "nei";
		},
		forced: true,
		forceDie: true,
		persevereSkill: true,
		logTarget: "source",
		content() {
			"step 0";
			trigger.source.draw(5);
			trigger.source.recover();
		},
	},

	sw_chestgold: {
		trigger: { player: "die" },
		filter: function (event, player) {
			return event.source && event.source.isIn() && event.source.identity == "fan" && player.identity == "nei";
		},
		forced: true,
		forceDie: true,
		persevereSkill: true,
		logTarget: "source",
		content() {
			"step 0";
			trigger.source.addMark("sw_getSkill", 20);
		},
	},

	sw_chestdiamond: {
		trigger: { player: "die" },
		filter: function (event, player) {
			return event.source && event.source.isIn() && event.source.identity == "fan" && player.identity == "nei";
		},
		forced: true,
		forceDie: true,
		persevereSkill: true,
		logTarget: "source",
		content() {
			"step 0";
			trigger.source.gainMaxHp();
			"step 1";
			trigger.source.recover(trigger.source.maxHp - trigger.source.hp);
		},
	},

	sw_chestlegend: {
		trigger: { player: "die" },
		skillAnimation: true,
		animationColor: "gray",
		filter: function (event, player) {
			return event.source && event.source.isIn() && event.source.identity == "fan" && player.identity == "nei";
		},
		forced: true,
		forceDie: true,
		persevereSkill: true,
		logTarget: "source",
		async content(event, trigger, player) {
			const target = trigger.source;
			event.videoId = lib.status.videoId++;
			game.broadcastAll((list, id, player) => {
				_status.characterlist = list;
				const filter = name => !_status.characterlist.includes(name);
				const dialog = ui.create.characterDialog('heightset', filter);
				if (game.me == player) dialog.open();
				dialog.videoId = id;
				ui.arena.classList.add('choose-character');
			}, _status.characterlist, event.videoId, target)

			const { result } = await target.chooseButton(true).set('ai', Math.random).set('dialog', event.videoId)
			if (result.links.length === 0) {
				result.links.push(_status.characterlist.randomGet())
			}
			game.broadcastAll('closeDialog', event.videoId);
			game.broadcastAll(() => {
				ui.arena.classList.remove('choose-character');
			});
			const { result: control } = await target.chooseControl(...lib.character[result.links[0]].skills).set('prompt', '请选择一个技能')
			await target.addSkills(control.control)
		},
	},

	sw_chestiron: {
		trigger: { player: "die" },
		skillAnimation: true,
		animationColor: "thunder",
		filter: function (event, player) {
			return event.source && event.source.isIn() && event.source.identity == "fan" && player.identity == "nei";
		},
		forced: true,
		forceDie: true,
		persevereSkill: true,
		logTarget: "source",
		content() {
			"step 0";
			var player = trigger.source;
			player.chooseBool("是否失去任意一个技能？").ai = function (event, player) {
				return false;
			};
			"step 1";
			var player = trigger.source;
			if (result.bool) {
				var list = [];
				var skills = player.getSkills(null, false, false).filter(skill => {
					const info = get.info(skill);
					if (!info || info.charlotte || !get.skillInfoTranslation(skill, player).length) return false;
					return true;
				});
				for (var skill of skills) {
					list.push([skill, '<div class="popup text" style="width:calc(100% - 10px);display:inline-block"><div class="skill">【' + get.translation(skill) + "】</div><div>" + lib.translate[skill + "_info"] + "</div></div>"]);
				}
				player.chooseButton([`请选择失去一个技能`, [list, "textbutton"]]).set("forced", true).set("selectButton", 1).set("skills", skills);

			}
			else {
				game.log(player, "放弃选择");
				event.finish();
			}
			"step 2";
			var player = trigger.source;
			if (result.bool) {
				var skills = result.links;
				player.removeSkills(skills.slice(0));
			}
		},
	},

	mofaLDW: {
		persevereSkill: true,
		trigger: {
			player: "changeHp",
		},
		filter(event, player) {
			return player.countMark("mofaLDW_used") < 3 && (player.hp == 1 || player.hp == player.maxHp);
		},
		mark: true,
		intro: {
			content(storage, player) {
				return `剩余可发动次数为${3 - player.countMark("mofaLDW_used")}`;
			},
		},
		onremove: true,
		subSkill: {
			used: {
				charlotte: true,
				onremove: true,
			},
			gainCount: {
				charlotte: true,
				onremove: true,
			},
		},
		GetAllSkills(player) {
			var list = {};
			var ownSkills = get.translation(player.getSkills(true, false, false));
			for (var key in lib.character) {
				if (!lib.character[key][3]) continue;
				var skills = lib.character[key][3];
				for (var i of skills) {
					// if (ownSkills.includes(i)) continue;
					if (!lib.translate[i]) continue;
					if (ownSkills.includes(lib.translate[i])) continue;
					list[i] = lib.translate[i];
				}
			};
			return list;
		},
		async content(event, trigger, player) {
			player.addSkill(event.name + "_used");
			player.addMark(event.name + "_used", 1, false);
			// 一些函数

			// 随机获取任意个键值
			function getRandomKeys(obj, num) {
				var keys = Object.keys(obj);
				var selectedKeys = [];
				var i;
				for (i = 0; i < num; i++) {
					var randomIndex = Math.floor(Math.random() * keys.length);
					selectedKeys.push(keys[randomIndex]);
					keys.splice(randomIndex, 1);
				}
				return selectedKeys;
			}
			// 获取不重复的中文字符
			function extractChineseCharacters(arr) {
				var chineseRegex = /[\u4e00-\u9fa5]/g;
				var chineseSet = new Set();

				arr.forEach(function (str) {
					var chineseChars = str.match(chineseRegex);
					if (chineseChars) {
						chineseChars.forEach(function (char) {
							chineseSet.add(char);
						});
					}
				});
				return Array.from(chineseSet);
			}

			// 随机从数组中获取元素
			function getRandomElements(arr, num) {
				var result = [];
				var len = arr.length;
				var indices = [];

				for (var i = 0; i < len; i++) {
					indices.push(i);
				}

				for (var j = 0; j < num; j++) {
					var randomIndex = Math.floor(Math.random() * indices.length);
					var index = indices[randomIndex];
					result.push(arr[index]);
					indices.splice(randomIndex, 1);
				}
				return result;
			}

			// 检查存在的技能
			function findWordCombinations(arrA, arrB) {
				var combinations = [];

				for (var i = 0; i < arrB.length - 1; i++) {
					for (var j = i + 1; j < arrB.length; j++) {
						var word1 = arrB[i] + arrB[j];
						var word2 = arrB[j] + arrB[i];
						// console.log(word1, word2);
						if (arrA.includes(word1)) {
							combinations.push(word1);
						}
						if (arrA.includes(word2)) {
							combinations.push(word2);
						}
					}
				}
				return combinations;
			}

			// 通过值找键
			function findKeysByValue(obj, value) {
				var keys = [];
				for (var key in obj) {
					if (obj.hasOwnProperty(key) && obj[key] === value) {
						keys.push(key);
					}
				}
				if (keys.length == 0) return null;
				return keys;
			}

			// ai自动选择
			function autoChoose(list, findWord) {
				var index = [];
				var list = list.map(i => i[1]);
				var findWord = findWord.randomGet();
				for (var i of findWord) {
					for (var j = 0; j < list.length; j++) {
						if (i != list[j]) continue;
						index.push(j);
					}
				}
				// console.log(index, list[index[0]] + list[index[1]]);
				return index;
			};

			// 获取完全没法组成技能的汉字
			function getCannotCharacters(arr, skills) {
				var index = [];
				var list = arr.map(i => i[1]);
				for (var name of skills) {
					for (var j of name) {
						for (var k = 0; k < list.length; k++) {
							if (j != list[k]) continue;
							index.push(k);
						}
					}
				}
				return index;
			};

			//技能部分
			var allCNSkills = [], ENSkills = lib.skill.mofaLDW.GetAllSkills(player);
			for (var key in ENSkills) {
				allCNSkills.push(ENSkills[key]);
			}
			// 性能挑战（划掉）
			while (true) {
				var skillsList = getRandomKeys(lib.skill.mofaLDW.GetAllSkills(player), 100);
				var CNSkills = [];
				for (var i of skillsList) {
					CNSkills.add(get.translation(i));
				}
				var CNCharacters = extractChineseCharacters(CNSkills);
				var randomCN = getRandomElements(CNCharacters, Math.min(CNCharacters.length, 50));
				var findWord = findWordCombinations(allCNSkills, randomCN);
				// 保底技能数 默认15
				if (findWord.length > 15) break;
			}
			var list = [];
			for (var i = 0; i < randomCN.length; i++) {
				list[i] = [i, randomCN[i]];
			}
			if (list.length == 0) {
				player.popup('纳尼？没有技能了？！');
				return;
			};
			var fun1 = (list) => {
				var per = 0;
				if (per == 0) return [];
				var filterEnd = getRandomElements(list, Math.floor(list.length * per));
				return filterEnd;
			};
			//game.broadcastAll(function (player) {
			//	player.forceCountChoose = { chooseButton: 30 };
			//}, player);
			event.time = lib.configOL.choose_timeout;
			await game.broadcastAll(() => {
				lib.configOL.choose_timeout = 30;
			});
			var buttonList = [`魔法:请选择至少两个汉字（推荐选两个汉字）`];
			var count = 0;
			for (var i = 0; i < Math.ceil(list.length / 10); i++) {
				buttonList.push([list.slice(count, (count + 10 >= list.length ? list.length : (count + 10))), 'tdnodes']);
				count += 10;
			}
			buttonList.push(`存在有${findWord.length}个技能`);

			event.videoId = lib.status.videoId++;
			game.broadcastAll(
				function (list, len, player, id) {
					if (game.me != player) {
						const buttonList = ui.create.dialog(`魔法:请选择至少两个汉字（推荐选两个汉字）`);
						var count = 0;
						for (var i = 0; i < Math.ceil(list.length / 10); i++) {
							buttonList.add([list.slice(count, (count + 10 >= list.length ? list.length : (count + 10))), 'tdnodes']);
							count += 10;
						}
						buttonList.add(`存在有${len}个技能`);
						buttonList.videoId = id;
					}
				},
				list,
				findWord.length,
				player,
				event.videoId
			);

			const links = await player.chooseButton(buttonList)
				.set('forced', true)
				.set('selectButton', [2, Infinity])
				.set('filterButton', function (button) {
					var list = _status.event.cannot;
					if (list.length == 0) return true;
					if (list.includes(button.link)) return true;
					return false;
				})
				.set('ai', () => {
					_status.tmp_mofaLDW_endTime = true;
				})
				.set('cannot', fun1(getCannotCharacters(list, findWord)))
				.forResult('links');
			//game.broadcastAll(function (player) {
			//	delete player.forceCountChoose;
			//	// delete _status.tmp_mofaLDW_endTime;
			//}, player);
			await game.broadcastAll((time, id) => {
				var dialog = get.idDialog(id);
				if (dialog) {
					dialog.close();
				}
				lib.configOL.choose_timeout = time;
			}, event.time, event.videoId);

			var fun2 = (player, end = false) => {
				if (!end) player.popup(`没有${CsSkill}`);
				else player.popup(`时间耗尽`);
				// player.chat(`可组成的技能有:${findWord}`);
				game.log(player, "魔力耗尽...创造失败...");
				game.log(`提示:可组成的技能有:${findWord}`);
			};
			if (!links || _status.tmp_mofaLDW_endTime) {
				fun2(player, true);
				delete _status.tmp_mofaLDW_endTime;
				return;
			}
			var CsSkill = '';
			for (var i of links) {
				CsSkill = CsSkill + list[i][1];
			}

			var findkey = findKeysByValue(ENSkills, CsSkill);
			if (findkey != null) {
				var introSkills = [];
				for (var i of findkey) {
					introSkills.push(get.skillInfoTranslation(i));
				}
				const index = findkey.length == 1 ? 0 :
					await player.chooseControl()
						.set('choiceList', introSkills)
						.set('prompt', `请选择一个版本的【${get.translation(findkey[0])}】`)
						.set('ai', () => get.rand(0, findkey.length - 1))
						.forResult('index');
				if (!index && index != 0) return;
				player.addSkill(findkey[index]);
				game.log(player, "使用魔法创造了技能", "#g【" + get.translation(findkey[index]) + "】");
				player.popup(get.translation(findkey[index]));
				player.addMark("mofaLDW_gainCount", 1, false);
				if (player.countMark("mofaLDW_gainCount") > 1) {
					//player.removeMark("sw_getSkillMaxcnt", 1, false);
					game.broadcastAll((player) => { player.storage.sw_getSkillMaxcnt--; }, player);
					game.log(player, "失去了一个技能槽上限");
				}
			} else {
				fun2(player);
			}
		},
	},
	mofaLDW_enhance: {
		persevereSkill: true,
		trigger: {
			player: "changeHp",
		},
		round: 1,
		filter(event, player) {
			return (player.hp == 1 || player.hp == player.maxHp);
		},
		onremove: true,
		subSkill: {
			used: {
				charlotte: true,
				onremove: true,
			},
		},
		GetAllSkills(player) {
			var list = {};
			var ownSkills = get.translation(player.getSkills(true, false, false));
			for (var key in lib.character) {
				if (!lib.character[key][3]) continue;
				var skills = lib.character[key][3];
				for (var i of skills) {
					// if (ownSkills.includes(i)) continue;
					if (!lib.translate[i]) continue;
					if (ownSkills.includes(lib.translate[i])) continue;
					list[i] = lib.translate[i];
				}
			};
			return list;
		},
		async content(event, trigger, player) {
			player.addSkill(event.name + "_used");
			player.addMark(event.name + "_used", 1, false);
			// 一些函数

			// 随机获取任意个键值
			function getRandomKeys(obj, num) {
				var keys = Object.keys(obj);
				var selectedKeys = [];
				var i;
				for (i = 0; i < num; i++) {
					var randomIndex = Math.floor(Math.random() * keys.length);
					selectedKeys.push(keys[randomIndex]);
					keys.splice(randomIndex, 1);
				}
				return selectedKeys;
			}
			// 获取不重复的中文字符
			function extractChineseCharacters(arr) {
				var chineseRegex = /[\u4e00-\u9fa5]/g;
				var chineseSet = new Set();

				arr.forEach(function (str) {
					var chineseChars = str.match(chineseRegex);
					if (chineseChars) {
						chineseChars.forEach(function (char) {
							chineseSet.add(char);
						});
					}
				});
				return Array.from(chineseSet);
			}

			// 随机从数组中获取元素
			function getRandomElements(arr, num) {
				var result = [];
				var len = arr.length;
				var indices = [];

				for (var i = 0; i < len; i++) {
					indices.push(i);
				}

				for (var j = 0; j < num; j++) {
					var randomIndex = Math.floor(Math.random() * indices.length);
					var index = indices[randomIndex];
					result.push(arr[index]);
					indices.splice(randomIndex, 1);
				}
				return result;
			}

			// 检查存在的技能
			function findWordCombinations(arrA, arrB) {
				var combinations = [];

				for (var i = 0; i < arrB.length - 1; i++) {
					for (var j = i + 1; j < arrB.length; j++) {
						var word1 = arrB[i] + arrB[j];
						var word2 = arrB[j] + arrB[i];
						// console.log(word1, word2);
						if (arrA.includes(word1)) {
							combinations.push(word1);
						}
						if (arrA.includes(word2)) {
							combinations.push(word2);
						}
					}
				}
				return combinations;
			}

			// 通过值找键
			function findKeysByValue(obj, value) {
				var keys = [];
				for (var key in obj) {
					if (obj.hasOwnProperty(key) && obj[key] === value) {
						keys.push(key);
					}
				}
				if (keys.length == 0) return null;
				return keys;
			}

			// ai自动选择
			function autoChoose(list, findWord) {
				var index = [];
				var list = list.map(i => i[1]);
				var findWord = findWord.randomGet();
				for (var i of findWord) {
					for (var j = 0; j < list.length; j++) {
						if (i != list[j]) continue;
						index.push(j);
					}
				}
				// console.log(index, list[index[0]] + list[index[1]]);
				return index;
			};

			// 获取完全没法组成技能的汉字
			function getCannotCharacters(arr, skills) {
				var index = [];
				var list = arr.map(i => i[1]);
				for (var name of skills) {
					for (var j of name) {
						for (var k = 0; k < list.length; k++) {
							if (j != list[k]) continue;
							index.push(k);
						}
					}
				}
				return index;
			};

			//技能部分
			var allCNSkills = [], ENSkills = lib.skill.mofaLDW.GetAllSkills(player);
			for (var key in ENSkills) {
				allCNSkills.push(ENSkills[key]);
			}
			// 性能挑战（划掉）
			while (true) {
				var skillsList = getRandomKeys(lib.skill.mofaLDW.GetAllSkills(player), 100);
				var CNSkills = [];
				for (var i of skillsList) {
					CNSkills.add(get.translation(i));
				}
				var CNCharacters = extractChineseCharacters(CNSkills);
				var randomCN = getRandomElements(CNCharacters, Math.min(CNCharacters.length, 50));
				var findWord = findWordCombinations(allCNSkills, randomCN);
				// 保底技能数 默认15
				if (findWord.length > 15) break;
			}
			var list = [];
			for (var i = 0; i < randomCN.length; i++) {
				list[i] = [i, randomCN[i]];
			}
			if (list.length == 0) {
				player.popup('纳尼？没有技能了？！');
				return;
			};
			var fun1 = (list) => {
				var per = 0;
				if (per == 0) return [];
				var filterEnd = getRandomElements(list, Math.floor(list.length * per));
				return filterEnd;
			};
			//game.broadcastAll(function (player) {
			//	player.forceCountChoose = { chooseButton: 30 };
			//}, player);
			event.time = lib.configOL.choose_timeout;
			await game.broadcastAll(() => {
				lib.configOL.choose_timeout = 60;
			});
			var buttonList = [`魔法:请选择至少两个汉字（推荐选两个汉字）`];
			var count = 0;
			for (var i = 0; i < Math.ceil(list.length / 10); i++) {
				buttonList.push([list.slice(count, (count + 10 >= list.length ? list.length : (count + 10))), 'tdnodes']);
				count += 10;
			}
			buttonList.push(`存在有${findWord.length}个技能`);
			buttonList.push(`增强版提示:${findWord}`);

			event.videoId = lib.status.videoId++;
			game.broadcastAll(
				function (list, findWord, player, id) {
					if (game.me != player) {
						const buttonList = ui.create.dialog(`魔法:请选择至少两个汉字（推荐选两个汉字）`);
						var count = 0;
						for (var i = 0; i < Math.ceil(list.length / 10); i++) {
							buttonList.add([list.slice(count, (count + 10 >= list.length ? list.length : (count + 10))), 'tdnodes']);
							count += 10;
						}
						buttonList.add(`存在有${findWord.length}个技能`);
						buttonList.add(`增强版提示:${findWord}`);
						buttonList.videoId = id;
					}
				},
				list,
				findWord,
				player,
				event.videoId
			);

			const links = await player.chooseButton(buttonList)
				.set('forced', true)
				.set('selectButton', [2, Infinity])
				.set('filterButton', function (button) {
					var list = _status.event.cannot;
					if (list.length == 0) return true;
					if (list.includes(button.link)) return true;
					return false;
				})
				.set('ai', () => {
					_status.tmp_mofaLDW_endTime = true;
				})
				.set('cannot', fun1(getCannotCharacters(list, findWord)))
				.forResult('links');
			//game.broadcastAll(function (player) {
			//	delete player.forceCountChoose;
			//	// delete _status.tmp_mofaLDW_endTime;
			//}, player);
			await game.broadcastAll((time, id) => {
				var dialog = get.idDialog(id);
				if (dialog) {
					dialog.close();
				}
				lib.configOL.choose_timeout = time;
			}, event.time, event.videoId);

			var fun2 = (player, end = false) => {
				if (!end) player.popup(`没有${CsSkill}`);
				else player.popup(`时间耗尽`);
				// player.chat(`可组成的技能有:${findWord}`);
				game.log(player, "魔力耗尽...创造失败...");
				game.log(`提示:可组成的技能有:${findWord}`);
			};
			if (!links || _status.tmp_mofaLDW_endTime) {
				fun2(player, true);
				delete _status.tmp_mofaLDW_endTime;
				return;
			}
			var CsSkill = '';
			for (var i of links) {
				CsSkill = CsSkill + list[i][1];
			}

			var findkey = findKeysByValue(ENSkills, CsSkill);
			if (findkey != null) {
				var introSkills = [];
				for (var i of findkey) {
					introSkills.push(get.skillInfoTranslation(i));
				}
				const index = findkey.length == 1 ? 0 :
					await player.chooseControl()
						.set('choiceList', introSkills)
						.set('prompt', `请选择一个版本的【${get.translation(findkey[0])}】`)
						.set('ai', () => get.rand(0, findkey.length - 1))
						.forResult('index');
				if (!index && index != 0) return;
				player.addSkill(findkey[index]);
				game.log(player, "使用魔法创造了技能", "#g【" + get.translation(findkey[index]) + "】");
				player.popup(get.translation(findkey[index]));
			} else {
				fun2(player);
			}
		},
	},
	boss_shenyi: {
		unique: true,
		mod: {
			judge: function (player, result) {
				if (_status.event.type == "phase") {
					if (result.bool == false) {
						result.bool = null;
					} else {
						result.bool = false;
					}
				}
			},
		},
		trigger: { player: "turnOverBefore" },
		priority: 20,
		forced: true,
		filter: function (event, player) {
			return !player.isTurnedOver();
		},
		content: function () {
			trigger.cancel();
			game.log(player, "取消了翻面");
		},
		ai: {
			noturn: true,
			effect: {
				target: function (card, player, target) {
					if (get.type(card) == "delay") return 0.5;
				},
			},
		},
	},

	boss_tingqin: {
		persevereSkill: true,
		audio: false,
		trigger: { global: "loseAfter" },
		init(player, skill) {
			if (player.name1 != "boss_caiwenji" && player.name2 != "boss_caiwenji") player.removeSkill(skill)
		},
		filter(event, player) {
			if (event.type != "discard") return false;
			if (event.getParent()?.getParent()?.name == "boss_tingqin_1") return false;
			if (event.player == player) return false;
			if (!player.countCards("he")) return false;
			for (var i = 0; i < event.cards2.length; i++) {
				if (get.position(event.cards2[i], true) == "d") {
					return true;
				}
			}
			return false;
		},
		direct: true,
		unique: true,
		gainable: true,
		content() {
			"step 0";
			if (trigger.delay == false) game.delay();
			"step 1";
			var cards = trigger.cards2;
			if (cards.length) {
				var maxval = 0;
				for (var i = 0; i < cards.length; i++) {
					var tempval = get.value(cards[i]);
					if (tempval > maxval) {
						maxval = tempval;
					}
				}
				maxval += cards.length - 1;
				var next = player.chooseToDiscard("he");
				next.set("ai", function (card) {
					return _status.event.maxval - get.value(card);
				});
				next.set("maxval", maxval);
				next.set("dialog", [get.prompt(event.name), "hidden", cards]);
				next.logSkill = event.name;
				event.cards = cards;
			}
			"step 2";
			if (result.bool) {
				player.gain(event.cards, "gain2", "log");
			}
		},
		ai: {
			threaten: 1.3,
		},
		group: ["boss_tingqin_1"],
		subSkill: {
			1: {
				persevereSkill: true,
				audio: false,
				trigger: { global: "useCardAfter" },
				filter(event, player) {
					if (player.name1 != "boss_caiwenji" && player.name2 != "boss_caiwenji") return false;
					if (player == event.player) return false;
					//console.log(event.player.getDiscardableCards(event.player, "he").length);
					if (!event.player.getDiscardableCards(event.player, "he").length) return false;
					if (event.cards) {
						for (var i = 0; i < event.cards.length; i++) {
							if (get.position(event.cards[i]) == "d") return true;
						}
					}
					return false;
				},
				direct: true,
				unique: true,
				content() {
					"step 0";
					if (trigger.delay == false) game.delay();
					"step 1";
					var next = player.chooseToDiscard(get.prompt(event.name), "he")
						.set("ai", function (card) {
							return 10 - get.value(card);
						});
					next.logSkill = event.name;
					//}
					"step 2";
					if (result.bool) {
						let target = trigger.player;
						const cardx = target.getDiscardableCards(target, "he");
						const num = target.maxHp;
						if (cardx.length) target.discard(cardx.randomGets(num));
					}
				},
				ai: {
					threaten: 1.3,
				},
			},
		}
	},

	boss_hujia: {
		audio: 2,
		persevereSkill: true,
		trigger: { player: "phaseZhunbeiBegin" },
		direct: true,
		unique: true,
		init(player, skill) {
			if (player.name1 != "boss_caiwenji" && player.name2 != "boss_caiwenji") player.removeSkill(skill)
		},
		filter: function (event, player) {
			if (player.name1 != "boss_caiwenji" && player.name2 != "boss_caiwenji") return false;
			if (!player.countCards("he")) return false;
			return true;
		},
		content: function () {
			"step 0";
			player.chooseCardTarget({
				position: "he",
				filterTarget: function (card, player, target) {
					if (player == target) return false;
					//if (!lib.character[target.name]) return false;
					return true;
				},
				filterCard: lib.filter.cardDiscardable,
				ai1: function (card) {
					return get.unuseful(card) + 9;
				},
				ai2: function (target) {
					//return player.countCards("h") < Math.max(...game.filterPlayer().map(i => count(i)));
					if (target.hasSkill("boss_hujia_baiban")) return 1 - target.maxHp * 0.001;
					return lib.skill.olmaozhu.countSkill(target);
				},
				prompt: get.prompt("boss_hujia"),
			});
			"step 1";
			if (result.bool) {
				var target = result.targets[0];
				player.logSkill("boss_hujia", target);
				player.line(target, "fire");
				if (target.hasSkill("boss_hujia_baiban")) {
					target.loseMaxHp();
				} else {
					//target.disableSkill("boss_hujia", lib.character[target.name][3]);
					target.addSkill("boss_hujia_baiban");
				}
				player.discard(result.cards);
			}
		},
		ai: {
			expose: 0.2,
		},
		subSkill: {
			baiban: {
				init: function (player, skill) {
					player.addSkillBlocker(skill);
					player.addTip(skill, "胡笳 技能失效");
				},
				onremove: function (player, skill) {
					player.removeSkillBlocker(skill);
					player.removeTip(skill);
				},
				superCharlotte: true,
				charlotte: true,
				skillBlocker: function (skill, player) {
					//return !lib.skill[skill].persevereSkill && !lib.skill[skill].charlotte;
					return lib.skill[skill] && !lib.skill[skill].superCharlotte && !lib.skill[skill].ruleSkill;
				},
				mark: true,
				marktext: "笳",
				intro: {
					name: "胡笳",
					content: function (storage, player, skill) {
						var list = player.getSkills(null, false, false).filter(function (i) {
							return lib.skill.boss_hujia_baiban.skillBlocker(i, player);
						});
						if (list.length) return "失效技能：" + get.translation(list);
						return "无失效技能";
					},
				},
				//sub: true,
				//sourceSkill: "boss_hujia",
			},
		}
	},

	boss_guihan: {
		audio: 2,
		unique: true,
		persevereSkill: true,
		skillAnimation: true,
		limited: true,
		animationColor: 'orange',
		enable: "chooseToUse",
		mark: true,
		derivation: ["boss_tingqin", "boss_huixin"],
		init(player, skill) {
			player.storage.boss_guihan = false;
			if (player.name1 != "boss_caiwenji" && player.name2 != "boss_caiwenji") player.removeSkill(skill)
		},
		filter: function (event, player) {
			if (player.name1 != "boss_caiwenji" && player.name2 != "boss_caiwenji") return false;
			if (event.type != "dying") return false;
			if (!player.isDying()) return false;
			if (player.storage.boss_guihan) return false;
			return true;
		},
		content: function () {
			"step 0";
			player.removeSkill("boss_guihan");
			player.recover(player.maxHp - player.hp);
			player.storage.boss_guihan = true;
			"step 1";
			player.draw(4);
			"step 2";
			for (var i = 0; i < game.players.length; i++) {
				game.players[i].removeSkill("boss_hujia_baiban");
				//delete game.players[i].storage.boss_hujia;
			}
			//if (game.bossinfo) {
			//	game.bossinfo.loopType = 1;
			//	_status.roundStart = game.boss;
			//}
			player.removeSkill("beige");
			player.removeSkill("boss_hujia");
			player.addSkill("boss_tingqin");
			player.addSkill("boss_huixin");
		},
		ai: {
			skillTagFilter: function (player) {
				if (player.storage.boss_guihan) return false;
			},
			save: true,
			result: {
				player: 4,
			},
		},
		intro: {
			content: "limited",
		},
	},
	boss_huixin: {
		persevereSkill: true,
		trigger: { player: 'loseEnd' },
		frequent: true,
		unique: true,
		init(player, skill) {
			if (player.name1 != "boss_caiwenji" && player.name2 != "boss_caiwenji") player.removeSkill(skill)
		},
		filter: function (event, player) {
			if (player.name1 != "boss_caiwenji" && player.name2 != "boss_caiwenji") return false;
			return _status.currentPhase != player;
		},
		content: function () {
			"step 0"
			player.judge();
			"step 1"
			if (result.color == 'black') {
				_status.currentPhase.loseHp();
			}
			else {
				player.recover();
				player.draw();
			}
		},
		ai: {
			effect: {
				target: function (card) {
					if (get.tag(card, 'loseCard')) {
						return [0.5, 1];
					}
				}
			}
		}
	},

	fanghua: {
		trigger: { player: "phaseJieshuBegin" },
		forced: true,
		persevereSkill: true,
		locked: false,
		unique: true,
		init(player, skill) {
			if (player.name1 != "boss_zhenji" && player.name2 != "boss_zhenji") player.removeSkill(skill)
		},
		filter: function (event, player) {
			return game.hasPlayer(function (current) {
				return current.isTurnedOver();
			});
		},
		content: function () {
			"step 0";
			event.players = get.players(player);
			event.num = 0;
			for (var i = 0; i < event.players.length; i++) {
				if (!event.players[i].isTurnedOver()) {
					event.players.splice(i--, 1);
				}
			}
			"step 1";
			if (event.players.length) {
				event.players.shift().loseHp();
				event.redo();
			}
			"step 2";
			if (
				game.getGlobalHistory("everything", evt => {
					if (evt.name != "die" || evt.player.identity != "fan") return false;
					return evt.reason?.getParent() == event;
				}).length > 0
			) {
				player.removeSkill("tashui");
				game.log(player, "失去了技能〖" + get.translation("tashui") + "〗");
				player.popup(get.translation("tashui"));
			}
		},
		group: ["fanghua_addMaxHp"],
		subSkill: {
			addMaxHp: {
				filter: function (event, player) {
					return (player.name1 == "boss_zhenji" || player.name2 == "boss_zhenji");
				},
				trigger: { global: 'loseHpAfter' },
				persevereSkill: true,
				forced: true,
				unique: true,
				content: function () {
					player.gainMaxHp();
				},
			},
		}
	},

	tashui: {
		audio: 2,
		persevereSkill: true,
		trigger: { player: ['useCard2', 'respondAfter'] },
		unique: true,
		popup: false,
		init(player, skill) {
			if (player.name1 != "boss_zhenji" && player.name2 != "boss_zhenji") player.removeSkill(skill)
		},
		filter: function (event, player) {
			if (player.name1 != "boss_zhenji" && player.name2 != "boss_zhenji") return false;
			return event.card && get.color(event.card) == "black";
		},

		content: function () {
			"step 0"
			player.chooseTarget(get.prompt('tashui'), function (card, player, target) {
				return player != target;
			}).ai = function (target) {
				//	if(target.isTurnedOver()) return -1;
				var player = _status.event.player;
				if (get.attitude(player, target) == 0 && !target.classList.contains('turnedover')) return 1;
				if (get.attitude(player, target) > 0) {
					if (target.classList.contains('turnedover')) return 3;
					//if (target.hasSkillTag('noturn')) return 1;
					return -1;
				}
				else {
					if (target.hasSkillTag('noturn')) return 0;
					if (target.classList.contains('turnedover')) return -1;
					return 1 / (target.getHp() == 0 ? 1 : target.getHp()) + 2;
				}
				return target.classList.contains('turnedover') ? -1 : 1;
			}
			"step 1"
			if (result.bool) {
				player.logSkill('tashui', result.targets, 'thunder');
				result.targets[0].turnOver();
			}
		},
		ai: {
			effect: {
				player: function (card) {
					if (get.color(card) == 'black') {
						return [1, 2];
					}
				}
			}
		}
	},
	lingbo: {
		init(player, skill) {
			if (player.name1 != "boss_zhenji" && player.name2 != "boss_zhenji") player.removeSkill(skill)
		},
		filter: function (event, player) {
			if (player.name1 != "boss_zhenji" && player.name2 != "boss_zhenji") return false;
			if (_status.currentPhase != player) return false;
			return event.num > 1;
		},
		persevereSkill: true,
		audio: 2,
		trigger: { player: ['damageBegin2', 'loseHpBegin'] },
		forced: true,
		content: function () {
			trigger.num = 1;
			//trigger.cancel();
		},
	},
	jiaoxia: {
		init(player, skill) {
			if (player.name1 != "boss_zhenji" && player.name2 != "boss_zhenji") player.removeSkill(skill)
		},
		audio: 2,
		trigger: { target: "useCardToTargeted" },
		filter: function (event, player) {
			if (!event.player) return false;
			if (event.player == player) return false;
			return event.card && get.color(event.card) == "red" && (player.name1 == "boss_zhenji" || player.name2 == "boss_zhenji");
		},
		persevereSkill: true,
		frequent: true,
		content: function () {
			player.draw(player.maxHp);
		},
	},

	boss_taoni: {
		forced: true,
		trigger: { global: "useCardAfter" },
		init(player, skill) {
			if (player.name1 != "boss_sunce" && player.name2 != "boss_sunce") player.removeSkill(skill)
		},
		filter(event, player) {
			return (
				game.hasPlayer(function (current) {
					return current.hp > player.hp && player.hp >= 1;
				})
			);
		},
		content: function () {
			var players = game.players.filter(current => {
				return current.hp > player.hp && current.hp > 1;
			}).sortBySeat();
			for (var p of players) {
				player.line(p);
				p.loseHp(p.hp - player.hp);
			}

		}
	},
	boss_hulaoguan: {
		loopType: 2,
		gameDraw: function (player) {
			if (player == game.zhu) return 8;
			if (player == game.zhu.previous) return 5;
			return 4;
		},
		loopFirst: function () {
			return game.zhu.nextSeat;
		},
		init: function () {
			lib.inpile.remove('wugu');
			lib.inpile.remove('taoyuan');
			lib.inpile.remove('bagua');
			lib.inpile.remove('tengjia');
			lib.inpile.remove('fangtian');
			lib.inpile.remove('muniu');

			lib.inpile.addArray(['wushuangfangtianji', 'shufazijinguan', 'hongmianbaihuapao', 'linglongshimandai', 'lianjunshengyan']);
			lib.inpile.sort(lib.sort.card);
			var equiplist = [];
			for (var i = 0; i < ui.cardPile.childElementCount; i++) {
				var node = ui.cardPile.childNodes[i];
				if (node.name == 'bagua') {
					node.init([node.suit, node.number, 'linglongshimandai']);
					equiplist.push(node);
				}
				else if (node.name == 'tengjia') {
					node.init([node.suit, node.number, 'hongmianbaihuapao']);
					equiplist.push(node);
				}
				else if (node.name == 'fangtian') {
					node.init([node.suit, node.number, 'wushuangfangtianji']);
					equiplist.push(node);
				}
				else if (node.name == 'muniu') {
					node.init([node.suit, node.number, 'shufazijinguan']);
					equiplist.push(node);
				}
				else if (node.name == 'wugu' || node.name == 'taoyuan') {
					node.init([node.suit, node.number, 'lianjunshengyan']);
				}
			}
			equiplist.randomSort();
			const next = game.createEvent('boss_jingjia');
			next.player = game.zhu;
			next.cards = equiplist;
			next.setContent(function () {
				'step 0'
				if (!cards.length) {
					event.finish(); return;
				}
				player.logSkill('boss_jingjia');
				event.num = 1.5;
				'step 1'
				var card = cards.shift();
				if (player.canEquip(card) && Math.random() < event.num) {
					player.equip(card);
					event.num = 0.5;
				}
				if (cards.length) event.redo();
			});
		}
	},
	//准备更改！！！！！！
	yueyin: {
		init(player, skill) {
			if (player.name1 != "boss_zhugeliang" && player.name2 != "boss_zhugeliang") player.removeSkill(skill)
		},
		persevereSkill: true,
		unique: true,
		mark: true,
		intro: {
			content: function (storage, player) {
				var str = "扣减" + (7 - player.countMark("xiangxing_count")) + "点体力后失去下一枚星；";
				str += "防止禳星伤害条件：" + lib.translate["xiangxing" + player.countMark("xiangxing") + "_info"];
				return str;
			},
			//markcount: function (storage, player) {
			//	return Math.max(0, 7 - player.countMark("xiangxing_count"));
			//},
			markcount(err, player) {
				return `${7 - player.countMark('xiangxing_count')}`;
			}
		},
		skipDamage: {
			x7: function (player) {
				return player.countCards("h") == 0;
			},
			x6: function (player, event) {
				if (event.hasNature) return event.hasNature("fire");
			},
			x5: function (player, event) {
				if (event.hasNature) return event.hasNature("thunder");
			},
			x4: function (player, event) {
				return event.name == "loseHp";
			},
			x3: function (player, event) {
				return game.hasPlayer(function (current) {
					return current != player && current.countCards("e") >= 4;
				});
			},
			x2: function (player) {
				return player.countCards("j") >= 1;
			},
			x1: function () {
				let res = true;
				for (var i = 0; i < game.players.length; i++) {
					if (game.players[i].identity == "fan" && game.players[i].hp != 1) res = false;
				}
				return res;
			},
		},
		ai: {
			combo: "xiangxing",
			neg: true,
			effect: {
				target(card, player, target) {
					if (!target.hasSkill("xiangxing") || !target.storage.xiangxing || target.storage.xiangxing_count < 6) return;
					switch (target.storage.xiangxing) {
						case 7:
							if (get.tag(card, "discard") || get.tag(card, "lose")) {
								if (player !== target) return [1, 0, 1, 6 / (1 + target.countCards("h"))];
							}
							if (get.tag(card, "damage") || get.tag(card, "losehp")) {
								if (target.countCards("h")) return [1, 7, 1, -7];
							}
							break;
						case 6:
							if (typeof card === "object" && game.hasNature(card, "fire")) return;
							if (get.tag(card, "damage") || get.tag(card, "losehp")) return [1, 6, 1, -6];
							break;
						case 5:
							if (typeof card !== "object" || game.hasNature(card, "thunder")) return;
							if (get.tag(card, "damage") || get.tag(card, "losehp")) return [1, 5, 1, -5];
							break;
						case 4:
							if (get.tag(card, "damage")) return [1, 2, 1, -2];
							if (get.tag(card, "losehp")) return [1, -4];
							break;
						case 3:
							if (get.tag(card, "damage") || get.tag(card, "losehp")) {
								if (!game.hasPlayer(current => {
									return current !== target && current.countCards("e") >= 4;
								})) return [1, 3, 1, -3];
							}
							break;
						case 2:
							if (typeof card === "object" && get.type(card) === "delay") {
								if (target.countCards("j")) return [1, -4];
							}
							if (get.tag(card, "damage") || get.tag(card, "losehp")) {
								if (target.countCards("j") <= 1) return [1, 2, 1, -3];
							}
							break;
						case 1:
							return [1, 2, 1, -3];
					}
				}
			}
		},
	},
	//屎山代码，谁爱优化谁优化
	xiangxing: {
		persevereSkill: true,
		unique: true,
		init(player, skill) {
			player.setMark("xiangxing", 7);
			player.setMark("xiangxing_count", 0);
			player.addSkill("xiangxing7");
			if (player.name1 != "boss_zhugeliang" && player.name2 != "boss_zhugeliang") player.removeSkill(skill)
		},
		mark: true,
		intro: {
			content: "当前有#枚星",
		},
		//trigger: { player: ["damageEnd", "loseHpEnd", "dying"] },
		trigger: { player: ["damageEnd", "loseHpEnd"] },
		forced: true,
		popup: false,
		content: function () {
			"step 0";
			//if (player.isDying()) {
			//	if (player.hasSkill("yueyin") && lib.skill.yueyin.skipDamage["x" + player.storage.xiangxing](player, trigger)) {
			//		event.goto(3);
			//	}
			//	player.removeSkill("xiangxing" + player.storage.xiangxing);
			//	player.storage.xiangxing--;
			//	player.storage.xiangxing_count = 0;
			//	player.updateMarks();
			//	if (player.storage.xiangxing) {
			//		player.addSkill("xiangxing" + player.storage.xiangxing);
			//	} else {
			//		player.awakenSkill("xiangxing");
			//	}
			//	player.popup("xiangxing");
			//	player.updateMarks();
			//	game.log(player, "失去了一枚星");
			//}
			//else {
			//	var num = trigger.num;
			//	if (num) {
			//		player.storage.xiangxing_count += num;
			//	}
			//	if (player.storage.xiangxing_count >= 7) {
			//		if (player.hasSkill("yueyin") && lib.skill.yueyin.skipDamage["x" + player.storage.xiangxing](player, trigger)) {
			//			event.goto(3);
			//		}
			//		player.removeSkill("xiangxing" + player.storage.xiangxing);
			//		player.storage.xiangxing--;
			//		player.storage.xiangxing_count = 0;
			//		player.updateMarks();
			//		if (player.storage.xiangxing) {
			//			player.addSkill("xiangxing" + player.storage.xiangxing);
			//		} else {
			//			player.awakenSkill("xiangxing");
			//		}
			//		player.popup("xiangxing");
			//		player.updateMarks();
			//		game.log(player, "失去了一枚星");
			//	} else {
			//		player.updateMarks();
			//		event.finish();
			//	}
			//}
			var num = trigger.num;
			if (num) {
				player.addMark("xiangxing_count", num);

				game.broadcastAll((player, num1, num2) => {
					player.setMark("xiangxing", num1);
					player.setMark("xiangxing_count", num2);
					player.updateMarks();
				}, player, player.countMark("xiangxing"), player.countMark("xiangxing_count"));

			}
			if (player.countMark("xiangxing_count") >= 7) {
				if (player.hasSkill("yueyin") && lib.skill.yueyin.skipDamage["x" + player.countMark("xiangxing")](player, trigger)) {
					event.goto(3);
				}
				player.removeSkill("xiangxing" + player.countMark("xiangxing"));
				player.storage.xiangxing--;
				player.storage.xiangxing_count = 0;
				if (player.storage.xiangxing) {
					player.addSkill("xiangxing" + player.countMark("xiangxing"));
				} else {
					player.awakenSkill("xiangxing");
				}
				player.popup("xiangxing");

				game.broadcastAll((player, num1, num2) => {
					player.setMark("xiangxing", num1);
					player.setMark("xiangxing_count", num2);
					player.updateMarks();
				}, player, player.countMark("xiangxing"), player.countMark("xiangxing_count"));

				game.log(player, "失去了一枚星");
			} else {
				game.broadcastAll((player, num1, num2) => {
					player.setMark("xiangxing", num1);
					player.setMark("xiangxing_count", num2);
					player.updateMarks();
				}, player, player.countMark("xiangxing"), player.countMark("xiangxing_count"));
				event.finish();
			}
			"step 1";
			var list = game.filterPlayer(c => c.isIn() && c.identity == "fan").sortBySeat();
			//var list = game.filterPlayer();
			//list.remove(player);
			//list.sort(lib.sort.seat);

			for (var i = 0; i < list.length; i++) {
				list[i].addTempSkill("sbfangzhu_baiban");
			}
			var list2 = [];
			for (var i = 0; i < list.length; i++) {
				list2.push(0);
			}
			for (var i = 0; i < 7 * list.length; i++) {
				list2[Math.floor(Math.random() * list2.length)]++;
			}
			event.list = list;
			event.list2 = list2;
			"step 2";
			if (event.list.length) {
				var target = event.list.shift();
				target.damage(event.list2.shift(), "thunder");
				player.line(target, "thunder");
				event.redo();
			}
			"step 3";
			var list = game.filterPlayer();
			for (var i = 0; i < list.length; i++) {
				if (list[i].identity == "fan") list[i].removeSkill("sbfangzhu_baiban");
			}
			//var num = player.maxHp - player.hp;
			//if (num > 0) player.recover(num);
			if (player.storage.xiangxing == 0) {
				player.maxHp = 3;
				player.update();
			}
		},
		//subSkill: {
		//	baiban: {
		//		charlotte: true,
		//		init(player, skill) {
		//			player.addSkillBlocker(skill);
		//			//player.addTip(skill, "放逐 技能失效");
		//		},
		//		onremove(player, skill) {
		//			player.removeSkillBlocker(skill);
		//			//player.removeTip(skill);
		//		},
		//		skillBlocker: function (skill, player) {
		//			return !lib.skill[skill].persevereSkill && !lib.skill[skill].charlotte;
		//		},
		//		mark: true,
		//		//inherit: "baiban",
		//		marktext: "逐",
		//		intro: {
		//			content: function (storage, player, skill) {
		//				var list = player.getSkills(null, false, false).filter(function (i) {
		//					return lib.skill.xiangxing_baiban.skillBlocker(i, player);
		//				});
		//				if (list.length) return "失效技能：" + get.translation(list);
		//				return "无失效技能";
		//			},
		//		},
		//	},
		//},
	},

	fengqi: {
		trigger: { player: ["phaseZhunbeiBegin", "phaseJieshuBegin"] },
		direct: true,
		async content(event, trigger, player) {
			var list = { basic: [], equip: [], trick: [], delay: [] };
			for (var i = 0; i < lib.inpile.length; i++) {
				var name = lib.inpile[i];
				var info = lib.card[name];
				if (info.autoViewAs || name == "yuansuhuimie") continue;
				if (lib.filter.cardEnabled({ name: name }, player)) {
					if (!list[info.type]) {
						list[info.type] = [];
					}
					list[info.type].push([get.translation(lib.card[name].type), "", name]);
				}
			}
			list.trick.sort(lib.sort.name);
			var dialog = ui.create.dialog("风起", [list.trick, "vcard"]);
			// for(var i in list){
			//		dialog.addText(get.translation(i)+'牌');
			//		dialog.add([list[i],'vcard']);
			// }
			var rand1 = Math.random() < 1 / 3;
			var rand2 = Math.random() < 0.5;
			var rand3 = Math.random() < 1 / 3;
			var rand4 = Math.random() < 1 / 3;

			var usednum = 0;
			var totalusenum = 1;

			while (usednum < totalusenum) {
				const result = await player.chooseButton(dialog).set("ai", function (button) {
					var name = button.link[2];
					if (player.hp <= 1) {
						switch (name) {
							case "zhiliaobo":
								return 1;
							case "dunpaigedang":
								return 0.8;
							case "nanman":
								return 0.5;
							default:
								return 0;
						}
					}
					if (rand4 && player.countCards("h") <= 1) {
						switch (name) {
							case "zengbin":
								return 1;
							case "wuzhong":
								return 0.8;
							default:
								return 0;
						}
					}
					if (player.hasSkill("qinglonglingzhu")) {
						if (rand2) return name == "chiyuxi" ? 0.8 : 0;
						return name == "jingleishan" ? 0.8 : 0;
					}
					if (rand2) return name == "wanjian" ? 0.8 : 0;
					return name == "nanman" ? 0.8 : 0;
				}).forResult();
				if (result.bool) {
					player.chooseUseTarget(result.links[0][2], true, false);
					usednum++;
				}
				else break;
			}
		},
		ai: {
			threaten: 3,
		},
	},
	gaiming: {
		trigger: { player: "judgeBefore" },
		direct: true,
		priority: 1,
		unique: true,
		content: function () {
			"step 0";
			event.cards = get.cards(7);
			player.chooseCardButton(true, event.cards, "改命：选择一张牌作为你的" + trigger.judgestr + "判定结果").ai = function (button) {
				if (get.attitude(player, trigger.player) > 0) {
					return 1 + trigger.judge(button.link);
				}
				if (get.attitude(player, trigger.player) < 0) {
					return 1 - trigger.judge(button.link);
				}
				return 0;
			};
			"step 1";
			if (!result.bool) {
				event.finish();
				return;
			}
			player.logSkill("gaiming", trigger.player);
			var card = result.links[0];
			event.cards.remove(card);
			var judgestr = get.translation(trigger.player) + "的" + trigger.judgestr + "判定";
			event.videoId = lib.status.videoId++;
			event.dialog = ui.create.dialog(judgestr);
			event.dialog.classList.add("center");
			event.dialog.videoId = event.videoId;

			game.addVideo("judge1", player, [get.cardInfo(card), judgestr, event.videoId]);
			for (var i = 0; i < event.cards.length; i++) event.cards[i].discard();
			// var node=card.copy('thrown','center',ui.arena).addTempClass('start');
			var node;
			if (game.chess) {
				node = card.copy("thrown", "center", ui.arena).addTempClass("start");
			} else {
				node = player.$throwordered(card.copy(), true);
			}
			node.classList.add("thrownhighlight");
			ui.arena.classList.add("thrownhighlight");
			if (card) {
				trigger.cancel();
				trigger.result = {
					card: card,
					judge: trigger.judge(card),
					node: node,
					number: get.number(card),
					suit: get.suit(card),
					color: get.color(card),
				};
				if (trigger.result.judge > 0) {
					trigger.result.bool = true;
					trigger.player.popup("改命成功");
				}
				if (trigger.result.judge < 0) {
					trigger.result.bool = false;
					trigger.player.popup("改命失败");
				}
				game.log(trigger.player, "的判定结果为", card);
				trigger.direct = true;
				trigger.position.appendChild(card);
				game.delay(2);
			} else {
				event.finish();
			}
			"step 2";
			ui.arena.classList.remove("thrownhighlight");
			event.dialog.close();
			game.addVideo("judge2", null, event.videoId);
			ui.clear();
			var card = trigger.result.card;
			trigger.position.appendChild(card);
			trigger.result.node.delete();
			game.delay();
		},
		ai: {
			effect: {
				target(card, player, target) {
					if (typeof card !== "object" || get.type(card) !== "delay") return;
					if (target.storage.xiangxing === 2 && target.storage.xiangxing_count > 4 && target.hasSkill("xiangxing") && target.hasSkill("yueyin")) return;
					return 0.13;
				}
			}
		}
	},



	boss_baonu: {
		unique: true,
		trigger: { player: 'changeHp', global: 'boss_baonuwash' },
		forced: true,
		priority: 100,
		fixed: true,
		group: 'boss_baonu_end',
		audio: 2,
		mode: ['identity', 'guozhan', 'boss', 'stone', 'versus'],
		init: function (player) {
			if (player == game.zhu) {
				lib.onwash.push(function () {
					if (!_status.boss_baonuwash) {
						_status.boss_baonuwash = true;
						_status.event.parent.trigger('boss_baonuwash');
					}
					else {
						_status.event.player.addSkill('boss_baonuwash');
					}
				});
				for (var i in lib.card) {
					if (lib.card[i].subtype == 'equip1') lib.card[i].recastable = true;
				}
			}
		},
		filter: function (event, player) {
			return player.hp <= 4 || _status.boss_baonuwash;
		},
		content: function () {
			'step 0'
			if (player.hp > 6) {
				game.delay();
			}
			'step 1'
			player.chooseControl('暴怒战神', '神鬼无前', function () {
				if (Math.random() < 0.5) return '神鬼无前';
				return '暴怒战神';
			}).set('prompt', '选择一个形态');
			'step 2'
			var hp = player.hp;
			player.removeSkill('boss_baonu', true);
			if (result.control == '暴怒战神') {
				game.broadcast(player => {
					player.init('boss_lvbu2');
				}, player)
				player.init('boss_lvbu2');
			}
			else {
				game.broadcast(player => {
					player.init('boss_lvbu3');
				}, player)
				player.init('boss_lvbu3');
			}
			if (hp > 6) {
				player.maxHp = hp;
				player.hp = hp;
			}
			player.update();
			ui.clear();
			if (player.isLinked()) player.link();
			if (player.isTurnedOver()) player.turnOver();
			player.discard(player.getCards('j'));
			'step 3'
			while (_status.event.name != 'phaseLoop') {
				_status.event = _status.event.parent;
			}
			game.resetSkills();
			_status.paused = false;
			_status.event.player = player;
			_status.event.step = 0;
			if (game.zhuinfo) {
				game.zhuinfo.loopType = 1;
				_status.roundStart = game.zhu;
			}
		},
		ai: {
			effect: {
				target: function (card, player, target) {
					if (get.tag(card, 'damage') || get.tag(card, 'loseHp')) {
						if (player.hp == 5) {
							if (game.players.length < 4) return [0, 5];
							var num = 0
							for (var i = 0; i < game.players.length; i++) {
								if (game.players[i] != game.zhu && game.players[i].hp == 1) {
									num++;
								}
							}
							if (num > 1) return [0, 2];
							if (num && Math.random() < 0.7) return [0, 1];
						}
					}
				}
			}
		},
		subSkill: {
			end: {
				trigger: {
					global: 'phaseEnd',
					player: 'phaseBeginStart',
				},
				forced: true,
				charlotte: true,
				popup: false,
				filter(event, player, triggername) {
					if (triggername === "phaseEnd" && event.player !== player) {
						return true
					}
					return event.parent.name !== 'boss_baonu_end'
				},
				content() {
					if (event.triggername === "phaseEnd" && trigger.player !== player) {
						player.phase()
					} else if (event.triggername === 'phaseBeginStart') {
						trigger.cancel()
					}
				}
			}
		}
	},
	"boss_jingjia": {},
	"boss_aozhan": {
		forced: true,
		locked: true,
		charlotte: true,
		group: ["boss_aozhan_wuqi", "boss_aozhan_fangju", "boss_aozhan_zuoji", "boss_aozhan_baowu"],
		subSkill: {
			wuqi: {
				mod: {
					cardUsable: function (card, player, num) {
						if (player.getEquip(1) && card.name == 'sha') return num + 1;
					},
				},
				sub: true,
			},
			fangju: {
				trigger: {
					player: "damageBegin4",
				},
				forced: true,
				filter: function (event, player) {
					return player.getEquip(2) && event.num > 1;
				},
				content: function () {
					trigger.num = 1;
				},
				sub: true,
			},
			zuoji: {
				trigger: {
					player: "phaseDrawBegin",
				},
				forced: true,
				filter: function (event, player) {
					return (player.getEquip(3) || player.getEquip(4));
				},
				content: function () {
					trigger.num++;
				},
				sub: true,
			},
			baowu: {
				trigger: {
					player: "phaseJudgeBefore",
				},
				forced: true,
				filter: function (event, player) {
					return player.getEquip(5);
				},
				content: function () {
					trigger.cancel();
					game.log(player, '跳过了判定阶段');
				},
				sub: true,
			},
		},
	},
	shenwei: {
		audio: 2,
		unique: true,
		trigger: { player: 'phaseDrawBegin' },
		forced: true,
		content: function () {
			trigger.num += Math.min(3, game.players.length - 1);
		},
		mod: {
			maxHandcard: function (player, current) {
				return current + Math.min(3, game.players.length - 1);
			}
		}
	},
	shenqu: {
		audio: 2,
		group: 'shenqu2',
		trigger: { global: 'phaseZhunbeiBegin' },
		filter: function (event, player) {
			return player.countCards('h') <= player.maxHp;
		},
		frequent: true,
		content: function () {
			player.draw(2);
		}
	},
	shenqu2: {
		trigger: { player: 'damageAfter' },
		direct: true,
		filter: function (event, player) {
			return player.hasSkillTag('respondTao') || player.countCards('h', 'tao') > 0;
		},
		content: function () {
			player.chooseToUse({ name: 'tao' }, '神躯：是否使用一张桃？').logSkill = 'shenqu';
		}
	},
	jiwu: {
		derivation: ['olqiangxi', 'retieji', 'decadexuanfeng', 'rewansha'],
		audio: 2,
		enable: 'phaseUse',
		filter: function (event, player) {
			if (player.countCards('h') == 0) return false;
			if (!player.hasSkill('olqiangxi')) return true;
			if (!player.hasSkill('retieji')) return true;
			if (!player.hasSkill('decadexuanfeng')) return true;
			if (!player.hasSkill('rewansha')) return true;
			return false;
		},
		filterCard: true,
		position: 'he',
		check: function (card) {
			if (get.position(card) == 'e' && _status.event.player.hasSkill('decadexuanfeng')) return 16 - get.value(card);
			return 7 - get.value(card);
		},
		content: function () {
			'step 0'
			var list = [];
			if (!player.hasSkill('olqiangxi')) list.push('olqiangxi');
			if (!player.hasSkill('retieji')) list.push('retieji');
			if (!player.hasSkill('decadexuanfeng')) list.push('decadexuanfeng');
			if (!player.hasSkill('rewansha')) list.push('rewansha');
			if (list.length == 1) {
				player.addTempSkill(list[0]);
				event.finish();
			}
			else {
				player.chooseControl(list, function () {
					if (list.contains('decadexuanfeng') && player.countCards('he', { type: 'equip' })) return 'decadexuanfeng';
					if (!player.getStat().skill.olqiangxi) {
						if (player.hasSkill('olqiangxi') && player.getEquip(1) && list.contains('decadexuanfeng')) return 'decadexuanfeng';
						if (list.contains('rewansha') || list.contains('olqiangxi')) {
							var players = game.filterPlayer();
							for (var i = 0; i < players.length; i++) {
								if (players[i].hp == 1 && get.attitude(player, players[i]) < 0) {
									if (list.contains('rewansha')) return 'rewansha';
									if (list.contains('olqiangxi')) return 'olqiangxi';
								}
							}
						}
					}
					if (list.contains('olqiangxi')) return 'olqiangxi';
					if (list.contains('rewansha')) return 'rewansha';
					if (list.contains('decadexuanfeng')) return 'decadexuanfeng';
					return 'retieji';
				}).set('prompt', '选择获得一项技能直到回合结束');
			}
			'step 1'
			player.addTempSkill(result.control);
			player.popup(get.translation(result.control));
		},
		ai: {
			order: function () {
				var player = _status.event.player;
				if (player.countCards('e', { type: 'equip' })) return 10;
				if (!player.getStat().skill.olqiangxi) {
					if (player.hasSkill('olqiangxi') && player.getEquip(1) && !player.hasSkill('decadexuanfeng')) return 10;
					if (player.hasSkill('rewansha')) return 1;
					var players = game.filterPlayer();
					for (var i = 0; i < players.length; i++) {
						if (players[i].hp == 1 && get.attitude(player, players[i]) < 0) return 10;
					}
				}
				return 1;
			},
			result: {
				player: function (player) {
					if (player.countCards('e', { type: 'equip' })) return 1;
					if (!player.getStat().skill.olqiangxi) {
						if (player.hasSkill('olqiangxi') && player.getEquip(1) && !player.hasSkill('decadexuanfeng')) return 1;
						if (!player.hasSkill('rewansha') || !player.hasSkill('olqiangxi')) {
							var players = game.filterPlayer();
							for (var i = 0; i < players.length; i++) {
								if (players[i].hp == 1 && get.attitude(player, players[i]) < 0) return 1;
							}
						}
					}
					return 0;
				}
			}
		}
	},
	xiuluo: {
		audio: 2,
		trigger: { player: 'phaseZhunbeiBegin' },
		direct: true,
		filter: function (event, player) {
			return player.countCards('j') > 0;
		},
		content: function () {
			"step 0"
			var next = player.discardPlayerCard(player, 2, 'hj', '是否一张手牌来弃置一张花色相同的判定牌？');
			next.filterButton = function (button) {
				var card = button.link;
				if (!lib.filter.cardDiscardable(card, player)) return false;
				if (ui.selected.buttons.length == 0) return true;
				if (get.position(ui.selected.buttons[0].link) == 'h') {
					if (get.position(card) != 'j') return false;
				}
				if (get.position(ui.selected.buttons[0].link) == 'j') {
					if (get.position(card) != 'h') return false;
				}
				return get.suit(card) == get.suit(ui.selected.buttons[0].link)
			};
			next.ai = function (button) {
				var card = button.link;
				if (get.position(card) == 'h') {
					return 11 - get.value(card);
				}
				if (card.name == 'lebu') return 5;
				if (card.name == 'bingliang') return 4;
				if (card.name == 'guiyoujie') return 3;
				return 2;
			};
			next.logSkill = 'xiuluo';
			"step 1"
			if (result.bool && player.countCards('j')) event.goto(0);
		}
	},

	boss_guixin: {
		trigger: { global: 'drawAfter' },
		forced: true,
		logTarget: 'player',
		usable: 30,
		init(player, skill) {
			if (player.name1 != "boss_caocao" && player.name2 != "boss_caocao") player.removeSkill(skill)
		},
		filter: function (event, player) {
			return event.result && event.result.length >= 1 && event.player != player;
		},
		content: function () {
			'step 0'
			//console.log(_status.event.getParent());
			//console.log(_status.event.getParent().cards);
			////event.cards = trigger.result;
			//trigger.player.chooseCard(
			//	function (card) {
			//		console.log(_status.event.getParent().cards);
			//		return _status.event.getParent().cards.includes(card);
			//	},
			//	"归心：交给" + get.translation(player) + "一张牌",
			//	true
			//);
			trigger.player.chooseCard('h', '归心：交给' + get.translation(player) + '一张牌', true);
			'step 1'
			if (result.bool) {
				player.gain(result.cards, trigger.player);
				trigger.player.$give(1, player);
			}
		}
	},
	xiongcai: {
		unique: true,
		trigger: { player: "phaseAfter" },
		direct: true,
		init: function (player) {
			player.storage.xiongcai = [];
			// player.storage.xiongcai2=0;
		},
		intro: {
			content: "characters",
		},
		content: function () {
			"step 0";
			// if(player.storage.xiongcai2<1){
			//		player.storage.xiongcai2++;
			//		event.finish();
			// }
			// else{
			//		player.storage.xiongcai2=0;
			// }
			"step 1";
			player.logSkill("xiongcai");
			var list = [];
			var list2 = [];
			var players = game.players.concat(game.dead);
			for (var i = 0; i < players.length; i++) {
				list2.add(players[i].name);
				list2.add(players[i].name1);
				list2.add(players[i].name2);
			}
			for (var i in lib.character) {
				if (lib.character[i][1] != "wei") continue;
				if (lib.character[i].isBoss) continue;
				if (lib.character[i].isMinskin) continue;
				if (player.storage.xiongcai.includes(i)) continue;
				if (list2.includes(i)) continue;
				list.push(i);
			}
			var name = list.randomGet();
			player.storage.xiongcai.push(name);
			player.markSkill("xiongcai");
			var skills = lib.character[name][3];
			for (var i = 0; i < skills.length; i++) {
				player.addSkill(skills[i]);
			}
			event.videoId = lib.status.videoId++;
			game.broadcastAll((player, name, id) => {
				var dialog = ui.create.dialog(
					'<div class="text center">' + get.translation(player) + "发动了【雄才】",
					[[name], "character"]
				);
				dialog.videoId = id;
			}, player, name, event.videoId);
			game.delay(2);
			"step 2";
			game.broadcastAll('closeDialog', event.videoId);
		},
	},
	xiaoxiong: {
		trigger: { global: 'useCardAfter' },
		forced: true,
		unique: true,
		forceunique: true,
		init(player, skill) {
			if (player.name1 != "boss_liubei" && player.name2 != "boss_liubei") player.removeSkill(skill)
		},
		filter: function (event, player) {
			var type = get.type(event.card, 'trick');
			return event.player != player && (type == 'basic' || type == 'trick');
		},
		content: function () {
			"step 0";
			player.gain(game.createCard(trigger.card), 'gain2');
			"step 1";
			player.draw();
			//player.recover();
		},
		group: 'xiaoxiong_damage',
		subSkill: {
			damage: {
				trigger: { global: 'phaseJieshuBegin' },
				forced: true,
				filter: function (event, player) {
					return event.player != player && event.player.countUsed() == 0;
				},
				logTarget: 'player',
				content: function () {
					trigger.player.damage();
				}
			}
		}
	},
	boss_zhangwu: {
		global: "boss_zhangwu_ai",
		trigger: { player: "damageEnd" },
		//check: function (event, player) {
		//	return event.source && event.source.isIn() && get.damageEffect(event.source, player, player) > 0;
		//},
		init(player, skill) {
			if (player.name1 != "boss_liubei" && player.name2 != "boss_liubei") player.removeSkill(skill)
		},
		check(trigger, player) {
			if (!trigger.player || !trigger.player.isIn()) return false;
			if (get.attitude(player, trigger.player) >= 1) return false;
			return !trigger.player.hasSkillTag("filterDamage", null, {
				player: player,
				card: trigger.card,
			});
		},
		filter: function (event, player) {
			return event.source && event.source.isAlive();
		},
		direct: true,
		logTarget: "source",
		content: function () {
			"step 0";
			game.log("aaaa");
			player
				.chooseToDiscard(get.prompt("boss_zhangwu", trigger.source), "he", [1, Infinity])
				.set("ai", function (card) {
					//if (get.attitude(player, target) < 0) return 8 - get.value(card);
					//if (trigger.source.getEquip("baiyin") != null || trigger.source.getEquip("rw_baiyin") != null) return 0;
					return 8 - get.value(card);
					//return trigger.source.countCards("he") + 1;
					//return 3
				})
				.set("logSkill", ["boss_zhangwu", trigger.source]);
			"step 1";
			if (result.bool) {
				var num = result.cards.length;
				var cnum = get.cnNumber(num);
				event.num = num;
				trigger.source.chooseToDiscard("he", "章武：弃置" + cnum + "张牌，或取消并受到" + cnum + "点伤害", num).set("ai", function (card) {
					if (!trigger.source.hasSkillTag("nodamage")) return 10 - get.value(card);
					return 0;
				});
			} else {
				event.finish();
			}
			"step 2";
			if (!result.bool) {
				trigger.source.damage(event.num);
			}
		},
		ai: {
			maixie: true,
			maixie_hp: true,
			effect: {
				target: function (card, player, target) {
					if (get.tag(card, "damage") && player.countCards("he") < target.countCards("he")) {
						return [0, 2];
					}
				},
			},
		},
	},
	boss_zhangwu_ai: {
		ai: {
			effect: {
				target: function (card, player, target) {
					if (get.tag(card, 'recover') && card.name != 'recover') {
						for (var i = 0; i < game.players.length; i++) {
							if (game.players[i].hasSkill('xiaoxiong') && get.attitude(target, game.players[i]) < 0) {
								return 'zeroplayertarget';
							}
						}
					}
				}
			}
		}
	},

	boss_nianrui: {
		trigger: { player: 'phaseDrawBegin' },
		forced: true,
		content: function () {
			trigger.num += 3;
		},
		ai: {
			threaten: 1.6
		}
	},
	boss_mengtai: {
		group: ['boss_mengtai_begin', 'boss_mengtai_draw', 'boss_mengtai_use',
			'boss_mengtai_discard', 'boss_mengtai_end'],
		subSkill: {
			begin: {
				trigger: { player: 'phaseZhunbeiBegin' },
				forced: true,
				popup: false,
				content: function () {
					player.storage.boss_mengtai_draw = true;
					player.storage.boss_mengtai_use = true;
				}
			},
			draw: {
				trigger: { player: 'phaseDrawBegin' },
				forced: true,
				popup: false,
				content: function () {
					player.storage.boss_mengtai_draw = false;
				}
			},
			use: {
				trigger: { player: 'phaseUseBegin' },
				forced: true,
				popup: false,
				content: function () {
					player.storage.boss_mengtai_use = false;
				}
			},
			discard: {
				trigger: { player: 'phaseDiscardBefore' },
				forced: true,
				filter: function (event, player) {
					if (player.storage.boss_mengtai_use) return true;
					return false;
				},
				content: function () {
					trigger.cancel();
				}
			},
			end: {
				trigger: { player: 'phaseJieshuBegin' },
				forced: true,
				filter: function (event, player) {
					if (player.storage.boss_mengtai_draw) return true;
					return false;
				},
				content: function () {
					player.draw(3);
				}
			}
		}
	},
	boss_nbianshen: {
		trigger: { global: 'roundStart' },
		forced: true,
		popup: false,
		priority: 25,
		fixed: true,
		filter: function (event, player) {
			if (player.name == 'boss_nianshou_heti' || player.storage.boss_nbianshen) return true;
			return false;
		},
		content: function () {
			if (player.storage.boss_nbianshen) {
				const hp = player.hp,
					maxHp = player.maxHp,
					hujia = player.hujia;
				game.broadcastAll((player, result) => {
					player.init(result);
				}, player, 'boss_nianshou_' + player.storage.boss_nbianshen_next)
				player.storage.boss_nbianshen.remove(player.storage.boss_nbianshen_next);
				if (!player.storage.boss_nbianshen.length) {
					player.storage.boss_nbianshen = ['jingjue', 'renxing', 'ruizhi', 'baonu'];
				}
				player.storage.boss_nbianshen_next = player.storage.boss_nbianshen.randomGet(player.storage.boss_nbianshen_next);
				player.hp = hp;
				player.maxHp = maxHp;
				player.hujia = hujia;
				player.update();
			}
			else {
				player.storage.boss_nbianshen = ['jingjue', 'renxing', 'ruizhi', 'baonu'];
				player.storage.boss_nbianshen_next = player.storage.boss_nbianshen.randomGet();
				player.markSkill('boss_nbianshen');
			}
		},
		intro: {
			content: function (storage, player) {
				var map = {
					jingjue: '警觉',
					renxing: '任性',
					ruizhi: '睿智',
					baonu: '暴怒'
				};
				return '下一个状态：' + map[player.storage.boss_nbianshen_next];
			}
		}
	},
	boss_nbianshenx: {},
	boss_jingjue: {
		trigger: {
			player: 'loseAfter',
			global: ['equipAfter', 'addJudgeAfter', 'gainAfter', 'loseAsyncAfter', 'addToExpansionAfter'],
		},
		forced: true,
		filter(event, player) {
			return event.player === player && _status.currentPhase != player;
		},
		content() {
			'step 0'
			player.judge()
			'step 1'
			if (result.color === 'red') {
				player.recover()
				event.finish()
			} else {
				player.chooseTarget('对一名角色造成一点火焰伤害', 1)
			}
			'step 2'
			if (result.bool) {
				result.targets[0].damage(1, 'fire')
			}
		}
	},
	boss_renxing: {
		trigger: { global: ['damageEnd', 'recoverEnd'] },
		forced: true,
		filter: function (event, player) {
			return true
		},
		content: function () {
			player.draw();
		}
	},
	boss_ruizhi: {
		trigger: { global: 'phaseZhunbeiBegin' },
		forced: true,
		filter: function (event, player) {
			return event.player != player && (event.player.countCards('h') > 1 || event.player.countCards('e') > 1);
		},
		content: function () {
			'step 0'
			player.line(trigger.player, 'green');
			game.broadcastAll(function (tr) {
				_status.trigger = tr
			}, trigger)
			var next = trigger.player.chooseCard(true, '选择保留一张手牌和一张装备区内的牌，然后弃置其它牌', 'he', function (card) {
				switch (get.position(card)) {
					case 'h': {
						if (ui.selected.cards.length) {
							return get.position(ui.selected.cards[0]) == 'e';
						}
						else {
							return _status.trigger.player.countCards('h') > 1;
						}
					}
					case 'e': {
						if (ui.selected.cards.length) {
							return get.position(ui.selected.cards[0]) == 'h';
						}
						else {
							return _status.trigger.player.countCards('e') > 1;
						}
					}
				}
			});
			var num = 0;
			if (trigger.player.countCards('h') > 1) {
				num++;
			}
			if (trigger.player.countCards('e') > 1) {
				num++;
			}
			next.selectCard = [num, num];
			next.ai = function (card) {
				return get.value(card);
			};
			'step 1'
			if (result.bool) {
				var he = [];
				var hs = trigger.player.getCards('h');
				var es = trigger.player.getCards('e');
				if (hs.length > 1) {
					he = he.concat(hs);
				}
				if (es.length > 1) {
					he = he.concat(es);
				}
				for (var i = 0; i < result.cards.length; i++) {
					he.remove(result.cards[i]);
				}
				trigger.player.discard(he);
			}
		}
	},
	boss_nbaonu: {
		group: ['boss_nbaonu_sha'],
		trigger: { player: 'phaseDrawBegin' },
		forced: true,
		priority: -1,
		content: function () {
			if (player.hp > 4) {
				trigger.num = 4 + Math.floor(Math.random() * (player.hp - 3));
			}
			else {
				trigger.num = 4;
			}
		},
		subSkill: {
			sha: {
				mod: {
					cardUsable: function (card, player, num) {
						if (card.name == 'sha' && player.hp < 5) return Infinity;
					}
				},
				trigger: { source: 'damageBegin1' },
				filter: function (event, player) {
					return event.card && event.card.name == 'sha' && event.notLink() && player.hp < 5;
				},
				forced: true,
				content: function () {
					trigger.num++;
				}
			}
		}
	},
	huanhua: {
		audio: 2,
		trigger: {
			global: "phaseBefore",
			player: "enterGame",
		},
		init(player, skill) {
			if (player.name1 != "boss_zuoci" && player.name2 != "boss_zuoci") player.removeSkill(skill)
		},
		filter(event, player) {
			return !player.storage.huanhua_chufa;
		},
		forced: true,
		unique: true,
		content: function () {
			player.storage.huanhua_chufa = true;
			for (var i = 0; i < game.players.length; i++) {
				if (game.players[i] == player || game.players[i].identity != "fan") continue;
				player.maxHp += game.players[i].maxHp;
				if (!game.players[i].name || !lib.character[game.players[i].name]) continue;
				var skills = lib.character[game.players[i].name][3];
				for (var j = 0; j < skills.length; j++) {
					if (!lib.skill[skills[j]].forceunique) {
						player.addSkill(skills[j]);
					}
				}
			}
			player.hp = player.maxHp;
			player.update();
		},
		group: ['huanhua2', 'huanhua3', 'huanhua4'],
		ai: {
			threaten: 0.8,
			effect: {
				target: function (card) {
					if (card.name == 'bingliang') return 0;
				}
			}
		}
	},
	huanhua2: {
		trigger: { player: 'phaseDrawBefore' },
		priority: 10,
		forced: true,
		popup: false,
		check: function () {
			return false;
		},
		content: function () {
			trigger.cancel();
		}
	},
	huanhua3: {
		trigger: { global: 'drawAfter' },
		forced: true,
		filter: function (event, player) {
			if (event.parent.name != 'phaseDraw') return false;
			return event.player != player;
		},
		content: function () {
			player.draw(trigger.num);
		}
	},
	huanhua4: {
		trigger: { global: 'discardAfter' },
		forced: true,
		filter: function (event, player) {
			if (event.parent.parent.name != 'phaseDiscard') return false;
			return event.player != player;
		},
		content: function () {
			player.chooseToDiscard(trigger.cards.length, true);
		}
	},
	"boss_hunzi": {
		skillAnimation: true,
		animationColor: "wood",
		audio: "hunzi",
		juexingji: true,
		derivation: ["reyingzi", "yinghun"],
		unique: true,
		trigger: {
			player: "phaseZhunbeiBegin",
		},
		filter: function (event, player) {
			return player.hp <= 2 && !player.storage.boss_hunzi;
		},
		forced: true,
		content: function () {
			player.removeSkill('boss_hunyou');
			player.removeSkill("boss_hunyou_dying");
			player.removeSkill("boss_hunyou_dieBegin")
			player.loseMaxHp();
			player.addSkill('reyingzi');
			player.addSkill('yinghun');
			game.log(player, '获得了技能', '#g【英姿】和【英魂】');
			game.log(player, '', '#y【魂佑】')
			player.awakenSkill('boss_hunzi');
			player.storage.boss_hunzi = true;
		},
		ai: {
			threaten: function (player, target) {
				if (target.hp == 1) return 2;
				return 0.5;
			},
			maixie: true,
			effect: {
				target: function (card, player, target) {
					if (!target.hasFriend()) return;
					if (get.tag(card, 'damage') == 1 && target.hp == 2 && !target.isTurnedOver() &&
						_status.currentPhase != target && get.distance(_status.currentPhase, target, 'absolute') <= 3) return [0.5, 1];
				},
			},
		},
	},
	"boss_jiang": {
		audio: "jiang",
		trigger: {
			global: ["respondEnd"],
		},
		charlotte: true,
		locked: true,
		init: function (player) {
			var a = window.setInterval(function () {
				if (player.hasSkill('boss_jiang')) {
					player.storage.boss_jiang = true;
				}
				else {
					game.addGlobalSkill('boss_jiang');
					game.addGlobalSkill('boss_jiang_use');
					window.clearInterval(a);
				}
			}, 1000);
		},
		filter2: function (event, player) {
			if (!event.respondTo[1]) return false;
			if (get.itemtype(event.cards) != 'cards') return false;
			if (['h', 'e', 'j'].contains(get.position(event.cards[0]))) return false;
			if (event.respondTo[1] && get.itemtype(event.respondTo[1]) != 'card') return false;
			if (event.respondTo[1] && ['h', 'e', 'j'].contains(get.position(event.respondTo[1]))) return false;
		},
		filter: function (event, player) {
			if (!player.storage.boss_jiang) return false;
			if (!event.respondTo) return false;
			if (get.color(event.card) != 'red') return false;
			if (event.respondTo[0] != player) {
				return event.player == player;
			}
			else {
				return event.player != player;
			}
		},
		frequent: true,
		content: function () {
			player.draw();
			if (!lib.skill.boss_jiang.filter2(trigger, player)) return;
			if (trigger.respondTo[0] != player) {
				if (trigger.respondTo[1] && get.position(trigger.respondTo[1]) == 'd') player.gain(trigger.respondTo[1], 'gain2');
			}
			else {
				if (get.position(trigger.cards[0]) == 'd') player.gain(trigger.cards, 'gain2');
			}
		},
		group: ["boss_jiang_use"],
		subSkill: {
			use: {
				trigger: {
					global: ["useCard"],
				},
				filter: function (event, player) {
					if (!player.storage.boss_jiang) return false;
					if (get.color(event.card) != 'red') return false;
					return player == event.player || event.targets.contains(player);
				},
				frequent: true,
				content: function () {
					player.draw();
					if (trigger.player != player && get.itemtype(trigger.cards) == 'cards' && get.position(trigger.cards[0]) == 'd') player.gain(trigger.cards, 'gain2');
				},
				sub: true,
			},
		},
	},
	"boss_hunyou": {
		forced: true,
		init: function (player, skill) {
			if (player.name1 != "boss_sunce" && player.name2 != "boss_sunce") {
				player.removeSkill(skill)
				return
			}
			player.hp = 1;
			player.storage.hp = player.hp;
			player.storage.maxHp = player.maxHp;
			player.update();
		},
		trigger: {
			player: ["damageBefore", "recoverBefore", "loseHpBefore", "loseMaxHpBefore", "gainMaxHpBefore"],
		},
		content: function () {
			trigger.cancel();
		},
		group: ["boss_hunyou_dying", "boss_hunyou_dieBegin"],
		subSkill: {
			dying: {
				trigger: {
					player: "dying",
				},
				silent: true,
				filter: function (event, player) {
					if (player.hp != player.storage.hp && player.storage.hp > 0) return true;
					return false;
				},
				content: function () {
					trigger.cancel();
					player.maxHp = player.storage.maxHp;
					player.hp = player.storage.hp;
					player.update();
				},
				sub: true,
				forced: true,
				popup: false,
			},
			dieBegin: {
				trigger: {
					player: "dieBegin",
				},
				silent: true,
				filter: function (event, player) {
					if (player.maxHp != player.storage.maxHp && player.storage.maxHp > 0) return true;
					return false;
				},
				content: function () {
					trigger.cancel();
					player.maxHp = player.storage.maxHp;
					player.hp = player.storage.hp;
					player.update();
				},
				sub: true,
				forced: true,
				popup: false,
			},
		},
	},
}

